Your boyfriend can invite you as a tourist – anyone can invite you as a tourist provided they can establish some kind of reason for the invitation. But he cannot sponsor you for permanent residence until your marriage is officially annulled.
Once your marriage is legally annulled you can indeed marry in Canada. A legal marriage in one country is usually recognized in all or most other countries though in many cases you’d have to get the marriage certificate translated into the local language and have that translation notarized.
If the sponsorship application has not yet been submitted when your entry stamp is expiring, you must leave the country. If you submit the sponsorship application first, then you can stay.