The U.S. electric system is adapting to a new wave of distributed energy resources, such as solar panels and energy storage. Some of these work together in localized networks known as microgrids—nearly 2,000 are now operating or planned across the country, according to one estimate.