I own a two family house and plan to convert to condos. What are the tax rules if I sell my unit, move to the rental, live there for two years and then sell it?

If you own a rental property for 20 years, can you then live in your rental property for 2 years and then sell it and get the capital gains exclusion?