Tesla is planning to build its electric cars in China.

"At some point in the next three or four years we'll be establishing local manufacturing in China," CEO Elon Musk said in Beijing. "China is very important to the future of Tesla."

Musk was in Beijing to mark the first deliveries of Tesla's Model S to customers in China, where the sports car sells for around $115,000.

Electric vehicle sales in the world's second biggest economy have been tepid so far, but many automakers see great potential. The country's middle class is expanding rapidly and is increasingly interested in luxury cars.

China also faces a growing air pollution problem, and the government is working to encourage the adoption of electric cars.

Yet much of China lacks the infrastructure needed to support them.

State media reported that Tesla (TSLA) is ready to help change that, with Musk pledging to launch a nationwide battery charging and service network by 2015.

"We're going to make a big investment in China in terms of charging infrastructure," Musk said.

The automaker has already built a supercharger network in the United States, making it easier for Tesla drivers to travel between major cities.

Related story: Will Tesla's bet on China pay off?

China isn't the only place Tesla wants to build a new factory.

It has plans for a massive U.S. facility that is expected to produce more lithium ion batteries annually by 2020 than were produced worldwide in 2013.

Tesla estimates the new factory will cost $4 billion to $5 billion and employ about 6,500 people. It could be located in either Arizona, Nevada, New Mexico or Texas.

Making more batteries, and reducing their cost, are vital to Tesla's ability to produce a cheaper car in numbers that could catapult the company into the ranks of the major automakers.