How does a battery produce electric energy?
First you should distinguish between proper batteries and a bit simple accumulators. In the first case we set-in real chemical reactions while in second case it is worked a system of capacitor(s).
In the battery happens particular reactions called reduction–oxidation (redox). In this type of reactions among two opportune chemical species (the species must take places separated in different parts of the battery) are generated an amount of free electrons for every single reaction and the sum of all reactions gives the total amount of charges (electrical power) that the batteries can furnish at every moment by its own limits of power output.