I am selling my primary at at approximately $170k profit after fees. I'm already under contract for a new primary in another state. However, the new house will close a month or more before my primary is closed / sold. Thus, I'm not putting much down on the new house, but will refinance within a few months on the new house and put more down to avoid PMI (broker is waving most fees if I refi within 90 days). Because of this, will I have to pay capitol gains on the $170k? What are the tax implications? Do I need to do a 1031 exchange?
Also, I am using all of the proceeds from my ESPP and options grants for a large portion of the down payment (because I won't have the $170k yet for selling my primary). Is there a way to get some of the taxes back that I've already paid on my options grant / sold stock or the shares I sold in end of 2015 from the ESPP?