Yes...If you take two magnets and orient them so that their like poles face each other, pushing them together will store energy. The energy you exerted to do this will be released when you move the poles apart again.
In the sun, magnetic fields are more slippery because they are anchored in gas, not in a solid 'magnet'. Fields can merge, short circuit, and cause nearby charged matter to be accelerated. The amount of energy stored in a magnetic field is given, in ergs/cc, by B^2/8 x pi where B is in gauss units. Example, a common 100 Gauss toy magnet, if it was completely demagnetized, would release 100^2/( 8 x 3.141) = 397 ergs of energy for each cubic centimeter of its volume. Sunspot fields are sometimes 10,000 Gauss and cover a volume measured in 10,000km on a side! This energy, liberated in solar flares in less than an hour, equals thousands of hydrogen bombs!
All answers are provided by Dr. Sten Odenwald (Raytheon STX) for the
NASA IMAGE/POETRY project.