Home sale - better as a primary residence or rental?

I'd like to sell my home sometime in the near future (1-5 years?) and it's currently being used as a 25% primary residence 75% rental (by renting out the remaining rooms). I am considering fully relocating to another state and turning the house into a 100% rental. However, I want to set myself up to retain as much of the property sale funds (including ~600k in gains) to use myself and not pay out in long term capital gains taxes when I sell the house. Would it be better to establish a 100% 2-year primary residence before selling OR 100% rental before selling (and perhaps use a 1031 exchange)? I'd like to retain as many of these funds as possible to use or convert to my new state of residence. What are my options, and what keeps the most $$ in my own pocket?