You can get an extension on the visa exemption for 30 more days.
And yes, you can apply for the retirement visa before you leave as well. However, everything is much easier if you do get the visa from your home country. This gives you up to 90 days to play with.
Live your best life in Thailand. Get help with Visas, accomodation, itineraties, retirement, dating and anything else in Thailand.