I want to know if this is legit or not. Here is my strategy:
Buy house A. Use it for investment purposes and either rent or flip it.
Execute a 1031 exchange and roll all of the proceeds into investment house B.
Convert investment house B into my primary residence for two years and then sell it.
Do I owe any capital gains on the profits made from investment house A? Investment house B? What takes precedence? The primary residence exclusion or the normal 1031 process?
In a fully tax deferred 1031 exchange, your potential capital gain in A is rolled into B. A 1031 exchange defers any tax on your capital gain until you sell B.
If you use B for a qualified investment purpose for a year or more (2 years would be better) before converting it to your primary residence, you do qualify for a capital gain exclusion on the sale of a primary residence only after 5 years of ownership AND 2 years occupancy as your primary residence.
The sale will not be totally tax free. That period of time that your property B was in service as a rental divided by the total years of ownership multiplied by your profit on the sale due to appreciation is the amount that may be excluded from capital gain subject to the $250K/$500K limit. The balance of your sale profit will be taxed at the long term capital gains rate for your marginal tax bracket.
Additionally, all the depreciation from A also rolled over to B, and when B is sold, all the cumulative depreciation will be recaptured at 25%.
You ask whether the 1031 exchange takes precedence over the primary residence exclusion. In this scenario, when you sell B, it is your primary residence at the time of the sale. A primary residence is not eligible to participate in a 1031 exchange. So, unless I misunderstood the question, a 1031 exchange would not apply here