Home Sale - Combining section 121 and 1031

Given that the home is used as a primary home (lived 3 out of last 5yrs) and then was rented for past 2yrs, is it possible to take the tax exemption (upto $250k for single or $500k for filing jointly) on the capital gains as a primary home and also do a 1031 exchange on the additional remaining capital gains?

 

Is it even allowed to combine the section 121 and 1031?

 

Thanks!