There are some cynics that believe that you cannot avoid tax. At least for capital gains and depreciation recapture there is a tried and true strategy to successfully avoid the supposedly inevitable tax. That strategy is simple. Do not sell the investment property. Hold it until you die. Upon death there is the stepped up basis. That means that your heirs' basis is the market value of the property at the time of your death. Since capital gains tax is the difference between market value and the cost of the property, when your heirs inherit your property the IRS finds no capital gains are owed because of the stepped up basis rules your heirs cost basis and market value is the same at the time of the inheritance. Now if the heirs keep the property for some time and the market value increases, they will then have capital gains unless they adopt the "hold until death" strategy.
If you adopt the "hold until death strategy", are you stuck with the same investments until you die? The answer is no. The IRS allows you to exchange properties tax free if you do not convert any of the property to cash and then decide to not invest that cash into the exchanged property. The money that some withdraw from their investment is called "boot" by the IRS. Originally taxpayers were required to actually exchange their property with other taxpayers. That was the requirement until a taxpayer named Starker came up with the idea of allowing a taxpayer to sell his property, have a independent person or entity hold the proceeds, and then reinvest the proceeds in another investment property. The IRS did not approve that approach, but the US Supreme Court did. As a result of that decision the IRS adopted section 1031 of the Internal Revenue Code that sets up the rules for an "exchange" which in reality is a sale and repurchase done in accordance with those rules. Wikipedia has a great article explaining those rules. Check it out at this link: http://en.wikipedia.org/wiki/Internal_Revenue_Code_section_1031
A big concern in doing an exchange is making sure that the "intermediary" which holds the proceeds of your sale pending the repurchase is reliable. In Colorado we have had a few "intermediaries" steal the funds. It is easy to pick a safe intermediary...you just need to know how to do that.
If you do not need to sell your investments to use the money for other things, it is quite easy to hold them for your entire lifetime. "1031 Exchanges" allow you the flexibility to change those investments over your life to hopefully make them work better for you.