Your first goal as an investor is to identify stock market opportunities. That's the point of investing, after all. If you can earn 15% to 20% annualized returns, you're elated.

But investing doesn't end there.

Taxes, fees, and trading costs add up over time. If you're not smart about your asset allocation, trading practices, withdrawal rates, and tax-advantaged vehicles, they will take a bite out of your real returns. And the returns from those after-tax, after-trading costs are, after all, what matter most. They may not be the numbers you brag to your friends about, but they sure are the numbers that pay the bills.

Get ahead, stay ahead
Let's say you were a shareholder of one or more of the runaway market successes of the past year: Finisar (NASDAQ:FNSR), Silver Wheaton (NYSE:SLW), and Cenveo (NYSE:CVO). (And if you held a position in any or all, congratulations are in order.)

Each of those stocks is up more than 100% since Aug. 31, 2005 -- and Finisar shareholders have seen a 340% increase. And while you should be toasting to those returns, a few bad moves can make your super paper returns a little more average.

Now let's say you want to take some of your Finisar off the table (perhaps because it's become such a big part of your portfolio). If you'd bought in October of last year and sold today, you would have to pay capital gains at your personal income tax level (up to 35%!). If, however, you wait a month, you qualify for long-term gains and would likely pay only 15%. On a $5,000 investment, those 30 days could save you more than nearly $2,000 (assuming the stock price stays the same).

Sure, that's a straightforward example, but let me assure you that the tax code is as complicated as it is long. If you've dollar-cost averaged into your positions, or if you want to re-characterize funds in your Roth IRA, you've got a pile of math and legalese to wade through.

Profit from your losses
As we all know and have experienced, stocks don't always go up. The stock market is full of disasters. From the Great Depression to the tech bubble, investors in every era have experienced the pain of financial loss.

But the good news is that a few stock market duds don't signal the end of your financial future. In fact, a few losers can actually help your returns, because you can use stock market losses to write off stock market gains. Want to unload Silver Wheaton or Cenveo? Maybe you also own Juniper Networks (NASDAQ:JNPR) or Chico's; these two stocks are down significantly over the past 12 months. It's only prudent to use your losses there to keep your gains out of the grubby hands of the tax man.

Or maybe you only own shares of Juniper and Chico's. If so, then this has been a rough year so far. But don't fret: Even those who have been crippled by such losses can get started on a plan to rebuild their savings and investments and achieve their retirement dreams.

One of the first steps in such a plan is to make sure your investments match your investing timeline. Chico's could be hugely successful again in the future. Unfortunately, it's currently working out some kinks. It might be a little while before the company is wowing analysts again. If you don't have some time -- read: you're in or very near retirement -- then Chico's may not be the place for your money.

If, however, you're a younger investor with some risk tolerance, consider taking a chance on a growth company such as Exelixis (NASDAQ:EXEL), which is not profitable right now, but can point to a stacked pipeline. There will be more bumps along the way with Exelixis than if you invest in a more proven health-care stock such as GlaxoSmithKline (NYSE:GSK), but you've still got some years in you, so why not swing for the fences?

Listen to legends
The world's greatest investors can't predict the future. Jack Bogle, founder of the hugely successful Vanguard Group, told Fool co-founder David Gardner, "I am a nervous investor. Nobody knows what will happen tomorrow or next year. ... But [with] four things -- diversification, tax efficiency, lower costs, a long time horizon -- you will capture the returns that this uncertain stock market is kind enough to deliver."

Bogle's words should guide us all. While investing is the foundation of wealth building, there's always work to be done to perfect your portfolio, balance your investments, and allocate your resources among taxable and tax-advantaged accounts in a way that meets your timeline and protects you from financial stumbles. By being smart with your gains, you can benefit most from your stock-picking successes.

The goal of our Motley Fool Rule Your Retirement service is to help you do just that. Former Wall Street financial planner Robert Brokamp will help make sure you don't get blindsided by arcane government regulations -- so that you earn the best real returns possible -- and plan for the perfect retirement. He'll even highlight specific stock picks from the Fool's best analysts along the way. To see exactly what Robert can offer, click here for a free 30-day trial. There is no obligation to subscribe.

This article was originally published June 27, 2006. It has been updated.

Tim Hanson does not own shares of any company mentioned in this article. Exelixis is a Rule Breakers recommendation. GlaxoSmithKline is an Inside Value recommendation. No Fool is too cool for disclosure.