After (XX) years of service to (the company), the time has come for me to retire. Please consider this letter formal notice of my intent to retire effective (date).
I hope that by giving notice relatively early that I will be able to assist in any necessary training and make this as smooth a transition as possible. Additionally, please don't hesitate to contact me after my retirement if you have any questions about (specialized knowledge).
My time with (the company) has been a pleasant, fulfilling experience. While I will surely enjoy the leisure time and intellectual pursuits afforded by retirement, I am sad to leave and will miss my colleagues, many of whom have become true friends.