That only works for relatively small amounts of (potential) energy, not grid-scale; the best / most efficient form of that is pumping water up into an elevated lake, that's the scalable version. But it's limited by availability of elevation and whatnot.