Ok, this might sound like a stupid question but I am legitimately confused. Imagine a circuit connected to a solenoid. When a circuit is closed (by a switch), there will be a quick increase in current, which will induce a magnetic field in the solenoid. The same magnetic field causes a change in the magnetic flux linkage of the coils, which then produces a back emf. Supposedly, this emf opposes the battery so the law of conservation of energy is not violated (my guess is that the kinetic energy supplied to the electrons by the battery is the source of the back emf?). However, when the circuit is opened, the same thing happens, but this time the emf is in the direction of the battery. I don't understand how this doesn't violate the law. As I see it, there is no energy in the circuit to be "transformed" into the back emf. Some texts I read said that opening the circuit is akin to an emf in the opposite direction as current suddenly drops, but there isn't any actual work done when opening the circuit?
If anyone can shed some light on the origin of the "energy" fueling this back emf, I will be very grateful.