@Donnie ********
2-3 months before your extension expires, you can start the checklist of things you need to get a retirement extension (e.g. seasoning of funds in your bank account). Your work permit expires on your last day of work, as does your Non-B extension (no matter the date mentioned on them) and they need to be cancelled at immigration, so what you do is you make sure you satisfy the list of requirements for a Non-O retirement extension and get it at your local immigration.
It totally depends on your immigration office if they'll let you do this before the last day of your employment, e.g. in Bangkok they might allow you to do so 1 week before your last day of work but in Nakhon Pathom (speaking from personal experience), they want you to come on your last day of work.
Hope that answers your question.