Deductions & credits

You have to live in home A for more than 2 years (731 days) of the 5 years prior to the sale. Assuming you moved in 7/1/17 and will sell on 4/30/18, that is 304 days.  Assuming you moved out 8/31/14, then the number of days between 4/30/13 (5 years back from the sell date) and 8/31/14 is 439.  That gives you 743 days which is more than the 2 years needed for the exclusion.  So your spouse can use her exclusion for home B and you can use your exclusion for home A.

You will need to determine the exact # of days based on your specific move and sell dates.  If my assumptions were too generous, it could very well be that you won't have 731 days until some future time.  And if you don't have 731 days, you can't use the exclusion at all.

However, even if you have 731 days of the past 5 years, there is a provision in the tax law that changes how the exclusion is handled if you move back into the home.  Instead of just accounting for deprecation, you also have to count the rental period as "non-qualified use."  This is unfortunately not well described in IRS publication 523 on home sales.  It's complicated and I think they gave up on trying to explain it.  But Turbotax does include the calculation.  

Basically, you will owe recapture on any part of the gain that is due to depreciation during the rental period.  Then you will also owe capital gains tax on the percent of gain due to the rental period (Hal suggests 45% based on your figures).  The gain left over after the depreciation recapture and the non-qualified period would be eligible for exclusion (if you meet the 731 days).