All of the batteries, cooling and safety systems, and other equipment are inside the casings, ready to load onto delivery trucks. “Our vehicle work lays a lot of the architectural foundation for this,” Mr. Straubel said. “It’s not as if we’re starting from scratch.”

The Mira Loma project came together quickly in part because California’s utilities already had several battery storage projects in the works, some involving Tesla. As the state has aggressively pursued the use of renewable energy sources, especially solar, to combat climate change, the traditional patterns of supply and demand have been upended.

California is on track to have an overabundance of energy during the day, when its many solar panels are producing energy, but that supply drops sharply as the sun sets, precisely when demand rises, with residents heading home to use appliances and, increasingly, to charge cars.

The state’s aging nuclear plants have been closed or are being phased out, putting even more pressure on utilities to find other ways to feed the grid. Storage is a natural solution, utility executives say, helping to smooth variations in the power flow from rooftop customers and when solar falls off and conventional plants have not yet filled the gap.

Ronald O. Nichols, president of Southern California Edison, said the utility was looking for more ways to use that energy, instead of curtailing solar production, “which makes no greenhouse-gas-reduction sense.” By 2024, the California system is expected to have far too much energy for at least a few hours each day, he said, adding, “We want to find a way to use that energy productively, and battery storage is certainly a piece of that.”