You must own and live in the property as your main home for two years of the previous five years from the date of sale in order to exclude the gain on the sale. That would mean that you would need to live in the property for 24 months of the 60 months prior to the sale. Since you rented it for 40 months, only 20 months are left. You would not meet the qualifications to exclude the gain on the sale based on residency.
See the following information from the IRS to learn more:
Publication 523
**Say "Thanks" by clicking the thumb icon in a post
**Mark the post that answers your question by clicking on "Mark as Best Answer"