Answer is: Carbon dioxide (CO₂) and energy (heat) is produced by combustion of fossil fuels, that energy is used for producing electricity (the heat energy of combustion is converted into mechanical energy).
For example, coal power plants use coal to heat water into steam, that steam than move a steam turbine, which generate electricity.