Image source: SunPower.

It's been a rough few years for most solar stocks. The industry has seen the biggest renewable energy developer, SunEdison, go bankrupt, the former largest module manufacturer, Yingli Green Energy, can't pay its debts, and the yieldco market that was supposed to provide long-term financing for projects has plunged in the past year.

Despite these setbacks, the future for solar is getting brighter. Around the world, solar energy is competing with fossil fuels head to head -- and winning. And that presents a big opportunity for investors.

There's incredible potential for solar

The first thing to think about is how big the sheer opportunity in solar energy is. The electricity industry is currently about $2 trillion per year, and the solar industry is just a fraction of that. Solar just passed 1% of U.S. electricity generation, and globally, it's still scratching the surface of its potential -- but that's changing.

Led by solar, the International Energy Agency (IEA) predicts that renewable energy will account for two-thirds of the new electricity capacity additions between 2016 and 2020, totaling 700 GW. For some perspective, the U.S. had a record year in solar last year and installed just 7.3 GW.  

In another analysis, according the GTM Research, global PV solar installations will grow from a total of 256 GW in 2015 to over 700 GW installed in 2020. And the driver is falling costs.

Image source: GTM Research.

Solar is now cost-competitive in most of the world

Driving the growth in the solar industry is a quickly improving cost competitiveness of solar projects. Lawrence Berkeley National Laboratory says new utility-scale solar projects in the U.S. now average $0.05 per kWh for energy, well below the average $0.12 per kWh the average retail customer pays, and on par with wholesale prices.  

In Mexico, a recent bid for energy projects had solar winning big with a weighted average price of 4.5 cents per kWh before location and other bonuses. The country will do another bid in June, and we could see even lower prices by then.  

Dubai's recent bid was the most shocking, recently coming in at 2.99 cents per kWh. There may be subsidies like free or cheap land and low-cost financing, but that's an incredibly low number no matter where it is.  

Solar costs have come down dramatically from the mid-2000s, when Germany was subsidizing projects to the tune of over $0.30 per kWh. Today, solar is standing on its own as an energy source, and that will unlock its growth potential.

Where to invest in this growth opportunity

There's no doubt a lot of companies in the solar industry have gone bust. Solyndra, Suntech Power, and SunEdison are just a few of the big names that have folded in the last few years. But emerging today are a few companies with a competitive advantage -- and even some profits for investors.

First Solar (FSLR 1.53%) and SunPower (SPWR -13.37%) are both module manufacturers who have a higher-efficiency product than most competitors and also develop their own projects. They also both have international exposure, allowing them to adapt to where solar makes the most financial sense in any given year.

As you can see below, revenue and net income can be very lumpy depending on when projects are sold, but given their strong balance sheets, superior technology, and international exposure, I think both will do well long term.

SPWR Net Income (TTM) Chart

SPWR Net Income (TTM) data by YCharts.

The even safer bet is 8point3 Energy Partners (CAFD), a yieldco created by First Solar and SunPower. It owns projects that have long-term contracts to sell energy and uses the resulting cash flow to pay dividends to investors. Since the cash flows and dividends are highly predictable and contracted in most cases for 20 years or more, this is a stock the risk-averse solar investor should love. The 6.3% dividend yield is extremely attractive, too.

No matter what solar company you invest in, expect volatility. This is still a relatively new market in energy, and stocks can swing wildly from even the smallest change in sentiment. But it's an industry with incredible opportunity and one more investors should start taking a closer look at.