Step one: it must start as a real rental
Intent at the time of the exchange is what matters. Acquire the property as a genuine investment and operate it as one — the widely used safe harbor (the same one covering vacation homes) is two years of renting it at least 14 days per year, with your personal use limited to 14 days or 10% of rental days annually. After establishing that record, converting it to your residence doesn't undo the exchange.
The special 5-year rule
Normally Section 121 lets you exclude gain after living in a home 2 of the last 5 years. But for a home acquired through a 1031 exchange, there's an extra gate: you must own the property at least five years before a 121 exclusion is allowed at all. Rent two years, live in it three, and you've satisfied both clocks.
The exclusion is prorated — and recapture survives
Even then, you don't get the full $250,000/$500,000 on everything. Gain is split between qualified use (years as your home) and non-qualified use (years as a rental after 2008), and only the qualified share is eligible for exclusion. Depreciation claimed during the rental years is never excludable — it's recaptured at sale regardless.