Elon Musk made a surprise appearance at the South by Southwest festival on Sunday where he discussed a wide range of topics, from colonizing Mars, to the risks artificial intelligence, to tough times at Tesla and SpaceX.

He also danced to his brother Kimbal Musk playing "My Little Buttercup," chatted about nuclear war, and amid all of that, called for a price on carbon.

Sustainable energy is "obviously really important” to the future of humanity, Musk said in a conversation with Jonathan Nolan, co-creator of the HBO show Westworld.

Musk believes clean energy solutions have reached a point where they're technologically viable, and distorted market conditions are the primary thing holding them back.

"The core technologies are there with wind, solar, with batteries," Musk said. "The fundamental problem is there's an unpriced externality in the cost of CO2."

"The market economics work very well if things are priced correctly,” he continued. “But when things are not priced correctly and something that has a real cost has zero cost, then that's where you get distortions in the market that inhibit the progress of other technologies."

Anything that puts carbon into the atmosphere should be subject to a carbon price, “which includes rockets, by the way -- so I'm not excluding rockets from this,” said Musk. The price can start low, but may need to be adjusted depending on whether or not it effectively reduces carbon emissions.

"In the absence of a price, we sort of pretend that digging trillions of tons of fossil fuels from deep under the earth and putting it into the atmosphere-- we're pretending that that has no probability of a bad outcome,” he said, adding that it’s up to people and their governments to make carbon pricing happen.

Musk pointed out in a matter-of-fact tone that there's a chance humanity returns to the Dark Ages at some point in the future, which is what’s driving his work on sustainable energy and space travel.

"We want to make sure there's enough of a seed of human civilization somewhere else to bring civilization back, and perhaps to shorten the length of the Dark Ages," said Musk.

To do that, it’s important to develop a “self-sustaining base” on the moon, or ideally, on Mars, he said. So it’s no coincidence that SpaceX is in the midst of building the first reusable interplanetary spaceship capable of traveling there.

Scientists have warned for years that climate change could result in unsustainable living conditions on Earth. Theoretical physicist Stephen Hawking believes humans will have to leave the planet in order to survive. Musk has warned of the dangers that climate change presents, as well.

In his SXSW talk, which took place as news swirled around U.S. negotiations with North Korea, Musk warned that the next dark age could be brought on by World War III. However, the greatest existential threat facing humanity isn't climate change or even a war, in his view: It's artificial intelligence.

The businessman said he isn’t typically a proponent of regulation, but in the case of AI there needs to be some kind of government oversight body to ensure that everyone is developing it safely.

No one would allow just anyone to build nuclear warheads, he said. "That would be insane."

"And mark my words, AI is far more dangerous than nukes."

On the positive side, Musk predicted AI would enable self-driving vehicle technology to encompass all modes of driving by the end of 2019, and that autonomous driving will be 100 percent to 200 percent safer than when a human is in control. The difficult piece is making sure AI isn’t used in nefarious ways.

"We have to figure out some way to ensure that the advent of digital super-intelligence is one which is symbiotic with humanity,” he said. “I think that's the single biggest existential crisis that we face, and the most pressing one."

While his SXSW talk was wide-ranging, Musk said that around 90 percent of his time is spent working on engineering and design at Tesla and SpaceX, with most other business decisions left to other executives.

Both companies are alive only “by the skin of their teeth,” he noted.

The billionaire said that in 2008 he only had around $30 million to $40 million left to his name and was forced to decide whether to invest in one company and let the other one die, or split the money between the two and risk both of them failing.

“If things went a little bit the other way, both companies would be dead,” Musk said. “When you put blood, sweat and tears into something, it’s like a child. Am I going to let one starve to death? I couldn’t do it, so I split the money between the two. Fortunately, they both pulled through.”

Both companies also still have a lot to prove.