It’s a rare feat when a government successfully turns a crisis into an opportunity.

In the past two years, the state of South Australia has suffered many blackouts, blamed on high demand and poor supply from both fossil-fuel and renewable generators. In response, the government switched on the world’s largest lithium-ion battery in December, and now it is launching a program to install solar panels on homes and distribute Tesla batteries to create the world’s largest “virtual power plant.”

Here’s how it works: Starting now, about 1,000 homes in public housing will receive Tesla batteries connected to solar panels installed on rooftops. The government will own the equipment, and residents will pay for the usage as they did before. Those who don’t consume all the energy produced by their solar panels can feed it back to the grid, and those who consume more can take extra from the grid.

At this scale, the program is not unusual. Many similar programs around the world benefit from some form of subsidies, helping users cut their energy bills and reduce their carbon footprint at the same time.

Where South Australia’s program differs is that, after the initial rollout, the state will open up the program to 50,000 homes in the state. In this phase, homeowners can either buy the equipment or lease it from an investor. In both cases, the solar panels and batteries will be connected to the grid.

If all goes according to plan, the state would have, in effect, a distributed power plant that can produce 250 MW of power from rooftop solar panels and store 650 MWh of energy in Tesla batteries. When it’s up and running—planned for 2021—it will be the world’s largest virtual power plant, about three times the size of the biggest such plant in existence today, according to Danny Price of Frontier Economics, which helped the government to create the program.

The government will invest around A$800 million ($635 million) to make it happen. Frontier Economics estimates that the state will save about A$180 million in electricity costs, because of increased competition and a more stable grid. Those savings will be passed onto consumers, whose electricity bills should fall by 30% for those participating in the program.

Solar power prices are increasingly becoming competitive with fossil-fuel power. However, without batteries, solar suffers because it is intermittent. Programs such as South Australia’s help to overcome this. And the more batteries the world installs, the cheaper they become—creating a virtuous cycle.

That said, batteries are only capable of handling variations in daily consumption. They are unable to store energy for months to deal with the huge inter-seasonal variations, such as peak demand for air conditioning in summer or heating in winter. For now, even Tesla’s huge battery in South Australia needs to be bailed out by fossil-fuel power once in a while.