Jim Hughes is about the last person you’d expect to find running a solar-power company. For starters, the 51-year-old Texan is a lawyer, not a physicist or a materials scientist. Then there’s the matter of the decade-plus he spent in senior jobs at Enron, followed by several years operating energy assets cleaved from its carcass. And lest there be any confusion, Hughes makes no effort to hide his contempt for the save-the-world, policy-driven mentality embraced by the “renewable” energy sector since its inception. “We need to quit talking about policy,” he says. “We need to focus on the fact that we can participate alongside traditional energy players on the basis of the existing economics. And we need to quit turning everything into a debate over climate change.” Markets may one day reward solar-panel makers for the benefits of lower carbon emissions, he says. “But the fact is, they don’t today. We can succeed without fighting that war.”

Peace has definitely broken out in the solar sector, stoked by the success of retail rooftop-installation companies like SolarCity (backed by Elon Musk) and manufacturers like First Solar, which survived a wave of bankruptcies among competitors. To get to this point, First Solar and others have endured the solar industry’s roller coaster of investor exuberance and massive government subsidies followed by manufacturing gluts, trade wars with China, plunging prices, and more recently a modest financial recovery. The company’s stock price trades for more than $50 a share, having bottomed out near $10 in mid-2012, around the time Hughes became CEO. (It exceeded $300 in 2008, during a period of maximum solar mania.) With 2013 earnings estimated to be just shy of $450 million on sales of $3.5 billion, First Solar is a stalwart — the biggest by revenues and profits — in an industry known for catastrophe.

First Solar is more than a survivor. It’s also a case study in the virtues of marrying wide-eyed technological optimism with patient capital that is willing to see a company through good times and bad. As one of the oldest surviving large-scale makers of what’s known as photovoltaic panels — sheets of glass covered with semiconductors that convert sunlight into electricity — the company has been a pioneer at several turns in its history. It championed a different type of panel technology from most of the rest of the industry, the same kind generally pursued by Solyndra, the infamously bankrupt startup that lost half a billion taxpayer dollars.

Yet First Solar is no Solyndra. Indeed, the latter might have fared better if it had been backed by a son of Sam Walton rather than by Uncle Sam. John Walton, one of the Wal-Mart founder’s four children, bought a controlling stake in First Solar 15 years ago, and his family continues to hold about 27% of the company’s stock today, a stake worth about $1.4 billion. (For comparison, the clan’s roughly 50% share of Wal-Mart today has a value of about $125 billion.)

The Walton family’s willingness to invest for the long term is a significant factor in First Solar’s success. That investment first nurtured the company through years of money-losing R&D and then supported a more recent pivot into a whole new line of business building large-scale power projects. That strategic shift kept First Solar healthy, giving it the ability to generate demand for its products. Says Shayle Kann of consulting firm GTM Research, which focuses on the business of sun power: “I don’t think First Solar would exist today, or have achieved the scale that it did, if it weren’t for the continuity of the Walton family’s financial support.”

Commercial-grade solar-panel technology has been around since the 1950s. It entered the public consciousness through images of panels on NASA spacecraft and Jimmy Carter’s short-lived installations on the roof of the White House. The standard technology then and now involves a multistep process that layers semiconductors on top of glass in an efficient but expensive fashion. In the 1980s a glass entrepreneur in Ohio named Harold McMaster started working on a one-step process that promised to dramatically lower the cost of solar panels.

This one-step process to produce so-called thin-film photovoltaics took years of revenue-less tinkering to perfect. Eventually it would be the technology of choice for a wave of Silicon Valley-funded solar companies, including Nanosolar, Miasole, and Solyndra, none of which grew into significant companies despite the combined billions invested in them. Meanwhile, the vast majority of the industry, including most big Chinese manufacturers today, would continue to use the more expensive but more reliable multistep process.

The company that became First Solar had a huge head-start on thin-film technology, and in the late 1990s it caught the eye of a venture capital firm called True North, which was funded by John Walton. The retail scion was an adventurer and restless soul who had served in the Special Forces in Vietnam and for a time as a Wal-Mart company pilot. He was the crusader of his family and an environmentalist long before Wal-Mart got religion on the subject.

True North bought a controlling stake in what became First Solar in 1999. Walton’s venture capital partner, Mike Ahearn, eventually became the company’s chief executive, and he says Walton was a constant presence. “He didn’t have a technology educational background,” recalls Ahearn. “But he was very curious about how things worked. The questions he asked were quite specific. You’d think he was an engineer.”

As chairman, Walton watched First Solar grow, eventually building some scale by selling panels into heavily subsidized markets in Europe, particularly Germany. He found it thrilling to invest in unproven companies, First Solar included. “He said all the time that venture investing was the whitewater rafting of business,” says Rick Chapman, who oversees the Walton family’s private business interests and joined the board of First Solar in 2012. But John Walton never was able to see First Solar fully shine. In 2005, a year before the company’s IPO, he died when the experimental aircraft he was piloting near his home in Wyoming crashed. At his death he was known mostly for his advocacy of the charter school movement. A touching remembrance of him in Fortune at the time mentioned only in passing that Walton “owned a solar-power company.”

Already, though, First Solar was one of the leading lights of the burgeoning renewable-energy industry. In the pre-financial-crisis boom for solar companies its market valuation peaked at $24.8 billion. But even then, says Ahearn, it maintained the long-term mentality forged during its extended incubation period.

The company was poised to earn its fattest profits yet on the strength of robust business in Europe in the late aughts. Demand and prices were soaring. But First Solar could see that the European gusher was transient and built on subsidies that would eventually expire.

So the company buckled down and made two simultaneous changes: First, it shifted its focus to a market — the U.S., mostly California — where the prices were considerably lower but demand was rising and less reliant on subsidies. Second, the company decided to invest heavily in utility-scale projects. Rather than merely selling panels, First Solar would build its own mega-installations, sometimes using its own money and other times on behalf of outside investors, and then sell the finished installations to independent power producers.

The strategic shift drew heat. “Wall Street criticized us for that,” Ahearn says, “but that move put us in the utility market and made us more than just a panel maker.” Still, the company’s transformation didn’t look good at first, especially because it shifted direction just before a damaging international price war broke out. With a flood of Chinese supply sending prices tumbling across the solar industry and the company taking big restructuring charges to shutter facilities, First Solar’s profits plummeted from $664 million in 2010 to a $40 million loss the following year. Many investors fled.

But the Waltons, who had sold shares before the fall, remained steadfast during the lean times. That paid intangible dividends. Because it has reliable cash flow, First Solar becomes a takeover target every time its stock dips. Yet would-be raiders never get very far: The Waltons aren’t interested in exiting. “Having nearly one-third of your equity owned by one shareholder who has shown a continuing commitment to the company through all kinds of ups and downs inevitably lends an air of credibility and stability,” says Hughes, the CEO. Asked whether the family would ever liquidate its stake, Chapman, its representative on the board, refrains from answering directly but leaves little confusion as to the answer. “The family thinks of First Solar as a legacy to John and is very proud of it,” he says. It’s a lucrative legacy: On an investment of $176 million, the family has sold $2.2 billion worth of stock so far and still holds shares worth $1.4 billion.

The industry turmoil shook First Solar. Top executives started leaving. Rob Gillette, Ahearn’s successor as CEO, abruptly departed, and the board brought Ahearn back on an interim basis before eventually recruiting Hughes in 2012.

The former Enron executive says he found a company whose strategy was sound but whose execution was lacking. In his view, First Solar had too few people at the top who knew about operating full-service energy companies, which First Solar had become. Hughes says that pitching giant projects calls for executives familiar with “decision-making processes” that are far faster and more complex than First Solar was used to. “We didn’t have those systems or processes in place two years ago,” he says. “We do today.”

Hughes has made a raft of changes. He continued shutting down manufacturing lines in Europe. He constructed a new sales force. And Hughes hired a new management team to replace the executives who had begun streaming out before he arrived (along with others who left after he took over). Of the nine executive officers at the company a year before Hughes arrived, precisely one remains, and she’s clearly been busy because she runs human resources.

The new executives largely come from outside the solar industry, in keeping with Hughes’s opinion that First Solar’s needs are those of an energy concern first and a renewable-energy entity second. Unsurprisingly, he has tapped talent from the Enron alumni network, including Joe Kishkill, who was named First Solar’s chief commercial officer in August.

Hughes embraces his Enron legacy, warts and all. At its best, particularly in some of its original businesses such as pipelines, Enron was known as an efficient operator. At its worst, of course, it was a corporate dissembler for the ages. That has made Hughes acutely aware of the need for candor in delivering bad news. “When you blow sunshine up somebody’s skirt continuously, with no real basis for it, they cease to believe you fairly rapidly,” he says. “Having lived through difficult times in the past with an organization,” he says, refraining from actually using the E-word, “that’s a lesson you learn.”

Today the times are much less difficult for First Solar. In part because of cost cuts and the changes implemented by Hughes and also because projects commissioned several years ago are now coming on line, the company has swung back into the black, with $450 million in profits over the past 12 months.

These days Hughes is most focused on the company’s massive construction projects in places like the Topaz Solar Farm in San Luis Obispo County, Calif., and the Desert Sunlight Solar Farm near Blythe, Calif. Those installations are the size of coal- or natural-gas-fueled electricity-generation plants, supplying power to merchant power companies, which resell it into the grids of nearby utilities. The projects fall under the mandate of a California program that requires the state’s utilities to produce a certain amount of renewable energy. It also benefits, like all such projects, from generous federal tax credits that make sun-powered electricity more competitive with electricity generated by coal or gas. (In the absence of these credits, solar power would cost significantly more than either.)

First Solar clearly benefits from those supports. But Hughes — who is quick to point out that fossil fuels enjoy government supports too — insists the company’s solar projects will be “sustainable” once they’re built. “We believe we survive and thrive in the North American market even without those [supports],” he says. Building large installations now accounts for 70% of First Solar’s revenues (the rest come from selling panels), and each is financed separately, often in conjunction with outside investors.

More recently the company has begun to try to replicate its success in the American Southwest by targeting previously untapped international markets, particularly India and Latin America. In some of those regions brownouts are the norm, and First Solar, which has pared its overhead in the past few years, sees the opportunity to take advantage of its reduced cost structure in ways that wouldn’t have made financial sense in the past.

First Solar’s very success in the Southwestern market now presents it with its biggest problem. At the beginning of the year Goldman Sachs analyst Brian Lee downgraded the company’s stock to a sell, calling it “mispositioned” relative to U.S. peers, including SunPower and SunEdison, which have fewer utility-size projects than First Solar.

The biggest cause of Lee’s worries: California utilities are nearing their mandatory minimum renewable production, which means First Solar will see less demand for giant installations. Lee argued that the company is ill-equipped to take advantage of the faster-growing rooftop installation business, and he contends that international expansion holds too little potential. First Solar declined to comment on the Goldman Sachs report.

These days the darling of the industry is SolarCity, which installs panels on houses (often at no charge to the homeowner in exchange for the revenue from selling the electricity that the panels produce). That’s a different business from First Solar’s, and First Solar can’t supply panels to SolarCity and other installers because its products aren’t suited to the task. (Thin-film solar panels are less efficient than the predominant technology, making them less cost-effective in tight spaces where rooftop real estate is at a premium.) Still, the potential is apparent, and last year First Solar took a step toward that market, buying a company called TetraSun, which uses technology more suitable to rooftops. First Solar plans to launch a rooftop installation business in Japan later this year or early in 2015.

As First Solar gears up for its next chapter, it has a key advantage: its balance sheet. In a slide prepared for Wall Street analysts, the company boasts of being the only significant net-cash-positive solar-panel maker. By contrast, SunEdison, SunPower, SunTech, and Yingli are all net debtors.

It’s a near certainty the solar business will endure some dark periods again. Hughes, the unsentimental operator, says his company is ready. “We want to build a business that can survive further turmoil,” he says. “Having a fortress balance sheet — and having a position where your financial viability cannot be questioned by anybody — we believe is a competitive advantage in the marketplace.” Lots of sunlight helps too.

This story is from the February 3, 2014 issue of Fortune.