First, they said electric cars didn’t go far enough. Now, they reach hundreds of miles. Then, they said electric cars were too expensive. Soon, owners will be able to make money while they sleep.

Electric cars are starting to generate income by storing power and selling it back to the grid. Over the lifetime of an electric vehicle, owners could earn enough to offset most of the purchase cost.

Electric cars are getting cheaper.

Thanks to rapidly declining prices, electric vehicles (EVs) are heading for the garages of middle-class homes. Tesla’s recently announced Model 3 comes with a $35,000 price tag. State and federal tax incentives drive down the cost even further. In California, the total comes to $25,000 after tax breaks, roughly the sticker price of a new Toyota Camry. That doesn’t take into account fuel savings.

To get an idea of how existing electric cars stack up against gas-powered vehicles, check out the Department of Energy’s Vehicle Cost Calculator. The numbers vary from car to car and depend on factors like the price of gas, the price of electricity and the fuel economy of vehicles being compared. At the improbably high end, Elon Musk says Tesla owners stand to save $10,000 on fuel over five years. Soon, owners will see additional benefits from selling stored power back to the grid.

Power grids need energy storage. With renewables, they are going to need a lot more.

Grid operators respond to peaks in consumer demand by ramping up additional gas or coal-fired power plants. This is dirty, expensive and generally a blunt tool tracking the hills a valleys of energy use. It more efficient to buy back electricity stored in EVs and homes batteries — what energy nerds call “distributed storage.”

Distributed storage is essential for integrating renewable energy into the grid. How do utilities meet consumer demand when the sun stops shining and the wind stops blowing? One tactic is to time-shift power use, running energy-intensive appliances when renewable output is at its highest. Another tactic is to store surplus power until it is needed.

In 2015, renewables accounted for two-thirds of new generating capacity in the United States, with more expectedin the years to come. Facing rising demand for energy storage, Tesla has begun producing home batteries and Nissan is slated to do the same. Car manufacturers are also looking to distributed storage to lower the operating costs of electric cars.

Electric cars can sell stored electricity back to the grid.

Electric cars can charge when demand for electricity is low and power is cheap and then sell energy back to the grid when demand peaks and the price of electricity shoots up. Together, a fleet of EVs can act like a power plant, leveling out gaps between supply and demand by dumping their stores of electrons onto the grid.

Researchers at the University of Delaware connected a handful of electric cars to the power grid using a two-way vehicle-to-grid interface. Each car earned around $5 a day storing power and selling it back to the grid. Nissan is piloting a similar project in the UK, outfitting electric cars and vans to sell electricity back to the grid. The company said owners of the all-electric Nissan Leaf could earn as much as $1,100 a year. That would amount to a whopping $10,000 over the life of a car battery.

When you’re done with your car battery, you can sell it.

Car batteries last around eight to 10 years. At the end of that time, they retain up to 80 percent of their storage capacity — too little to be useful to drivers, but enough that they can be repurposed as home batteries. A thriving aftermarket for car batteries could help shrink the cost of EV ownership.

One possibility is that manufacturers reuse or resell old batteries, using the proceeds to help defray the cost of replacement. BMW is spearheading a program that offers the grid energy storage from new electric cars and used EV batteries. GM recently deployed a set of retired Chevy Volt batteries, wind turbines and a solar array to power the administration building at its Enterprise Data Center.

Owners could also sell retired car batteries themselves. FreeWire, a California startup, is buying old batteries at $100 per kWh and using them to build mobile EV charging stations. At that price, owners of a Chevy Bolt could earn nearly $5,000 for a car battery reduced to 80 percent of its initial capacity.

This is good news for sales of electric cars.

Declining prices, fuel savings and a growing market for battery storage are conspiring to make electric vehicles more affordable, helping to drive up consumer demand. Tesla has received nearly 400,000 preorders for its Model 3, wedging open the EV market. Vacuum manufacturer Dyson is now rumored to be developing an electric car. And French oil and gas company Total just bought battery manufacturer Saft for almost $1 billion. Analysts project a dramatic rise in EV sales in over the next decade.

Widespread adoption of EVs will lead to more charging stations, better vehicle-to-grid interfaces and a wider market for used batteries. This, in turn, will further drive up sales, producing a virtuous circle of falling costs and improved performance.

Watch out, gas guzzlers. Your days are numbered.

Jeremy Deaton writes for Nexus Media, a syndicated news service covering climate, energy, policy, art and culture. You can follow him @deaton_jeremy.