Capital gains from selling a house where lived in and rented out

When selling a house where you have lived in it less than 2 years, and rented it out for several years subsequently, how can you best avoid capital gains tax? Is there anything other than taking partial exclusions that you can do? When pay the capital gains tax - at time of sale or April 15?