Over the past few decades, we've seen alternative-energy sources such as solar, wind, and biodiesel evolve into legitimate power sources that could have a big impact on how human beings use energy. World energy needs are expected to increase dramatically by 2050, so now could still be a great time to get in to the companies that stand to benefit the most as alternative-energy technologies continue to involve and become widely adopted. Here are four companies for investing in the future of energy that could pay off tremendously over the years.

Solar is scalable and getting more affordable
According to the U.S. Energy Information Administration (EIA), world energy demand is expected to increase by more than 50% by 2040, and the portion of energy that comes from alternative sources is expected to climb from 11% to more than 15% in that time period. And, solar is one of the most logical choices to meet the growing need.Solar systems are durable (no moving parts), they can be installed virtually anywhere there is abundant sun, and the panels themselves are continually becoming more affordable and efficient.

Along with wind power, solar is one of the two forms of alternative energy that is both scalable and efficient on the level we need it to be and cost-effective enough to make sense. When investing in solar stocks, you can choose a company that makes solar panels and equipment, such as First Solar (NASDAQ: FSLR), or a company that sells these items, such as SolarCity (NASDAQ: SCTY).

First Solar is an excellent play on the growing solar industry, and the company has had some very promising developments recently. First, Apple (AAPL -1.22%) announced that it's investing $850 million in a solar farm that First Solar is constructing. And it was announced that First Solar and rival SunPower (SPWR -2.21%) are joining forces to create a "yieldco," which will own 432 million megawatts of solar projects and pay dividend income to shareholders.

First Solar is continually improving the efficiency of its solar panels and is also figuring out ways to make its manufacturing processes more cost-effective. First Solar is profitable, and it not only has very little debt, but it's also sitting on a $2 billion cash stockpile. After some very strong stock performance over the past few months, First Solar trades for 21.2 times 2015's expected earnings, but if you back out the cash, the business itself is trading at a forward multiple of just 15.4, which is pretty cheap for a company with virtually limitless growth potential.

The consumer side of solar
SolarCity is an investment in the consumer end of solar. The company sells, engineers, and installs solar systems for residential and commercial applications and has a unique business model in which it leases solar systems to consumers in order to generate years of future cash flow. And, SolarCity is making large investments in solar panel manufacturing, so it has some exposure to all areas of the business.

The reason I think SolarCity is risky is that it's in the very early stages of its business, and like many young, high-potential businesses, it isn't making money -- yet. However, there are a few things shareholders should keep in mind. First, the losses look pretty dramatic (more than $12 per share over the next few years), but are largely due to SolarCity's favorable tax treatment, which allows for increased depreciation of assets, so the current losses should be taken with a grain of salt. And more importantly, SolarCity's business model is based on adding customers and creating a growing, stable revenue stream over time. In a nutshell, investors should pay much more attention to customer growth than to the "losses" the company reports.

However, investors' patience may pay off. SolarCity has grown its sales by an average annual rate of about 42% over the past five years and is projected to do even better in the future. Analysts at S&P forecast that SolarCity's revenue will rise 87% this year, and another 73% in 2016. So for those with the risk tolerance, SolarCity could turn out to be a home run if the explosive growth continues. And, with an addressable market of $60 billion, the potential is certainly there.

Just remember when investing in solar companies like these that you're investing in a very young industry and some growing pains are to be expected. However, some are in a better position than others to make it through any short-term headwinds. For example, First Solar has paid down a significant amount of its debt and is free cash flow positive, so it is very well-equipped to ride out any sector weakness.  These stocks could certainly experience some price swings over the coming years, but I truly believe that investors with time to let the industry mature will be very glad they got in early in the game.

A different kind of utility company
NextEra Energy
(NEE 0.45%) is a large utility company, with 42,500 MW of generating capacity, and nearly 5 million customers. The company is the largest generator of renewable energy in North America.

Solar makes up a small portion of the company's power generation, but 17% of the company's capacity comes from wind. Natural gas and nuclear power make up the bulk of the current profile, but there is a large backlog of planned wind and solar projects. In 2015 and 2016 alone, there are signed contracts for 2,115 MW of wind and solar projects set for delivery.

NextEra has done very well for its shareholders, producing an average total return of 13.9% per year over the past decade, including an 8.4% average dividend increase. With the cost of solar and wind power becoming more competitive with traditional sources, now may be a great time to get in for the long haul.

Source: NextEra Energy.

A less-direct play could be a safer alternative to solar companies
If you want to invest in the future of energy but owning individual solar stocks is a bit too risky for you, consider an "indirect" investment in solar. There are many major corporations with substantial solar operations that can offer safety and stability, as well as the opportunity to profit as the alternative-energy industry evolves.

For example, General Electric (GE -3.19%) has a large solar operation, manufacturing solar panels and a variety of related equipment. GE is also one of the largest manufacturers of wind turbines. The company's GE Wind division has installed more than 25,000 turbines in 31 countries, capable of generating more than 38 gigawatts of power.

GE has also invested heavily in renewable-energy projects, including some of First Solar's, and plans to commit $1 billion per year going forward to investment in alternative energy. So far, GE has committed about $10 billion to alternative-energy investments, with 80% of that amount going to wind power projects.

Just a starting point
This is by no means an exhaustive list of the stocks that could perform incredibly well over the coming decades as the future of energy becomes a reality. Alternative energy is expected to grow into a multi-trillion-dollar industry, and there will probably be many winners. However, I think these companies provide excellent exposure to the future of energy without exposing you to an incredible amount of risk.