The energy spectrum of the cosmic microwave background (CMB) allows constraining episodes of energy release in the early Universe. In this paper we revisit and refine the computations of the cosmological thermalization problem. For this purpose a new code, called CosmoTherm, was developed that allows solving the coupled photon-electron Boltzmann equation in the expanding, isotropic Universe for small spectral distortion in the CMB. We explicitly compute the shape of the spectral distortions caused by energy release due to (i) annihilating dark matter; (ii) decaying relict particles; (iii) dissipation of acoustic waves; and (iv) quasi-instantaneous heating. We also demonstrate that (v) the continuous interaction of CMB photons with adiabatically cooling non-relativistic electrons and baryons causes a negative mu-type CMB spectral distortion of DI_nu/I_nu ~ 10^{-8} in the GHz spectral band. We solve the thermalization problem including improved approximations for the double Compton and Bremsstrahlung emissivities, as well as the latest treatment of the cosmological recombination process. At redshifts z <~ 10^3 the matter starts to cool significantly below the temperature of the CMB so that at very low frequencies free-free absorption alters the shape of primordial distortions significantly. In addition, the cooling electrons down-scatter CMB photons introducing a small late negative y-type distortion at high frequencies. We also discuss our results in the light of the recently proposed CMB experiment Pixie, for which CosmoTherm should allow detailed forecasting. Our current computations show that for energy injection because of (ii) and (iv) Pixie should allow to improve existing limits, while the CMB distortions caused by the other processes seem to remain unobservable with the currently proposed sensitivities and spectral bands of Pixie.