The persistent thermal luminosity of magnetars and their outbursts suggest the existence of some internal heat sources located in their outer crust. The compression of matter accompanying the decay of the magnetic field may trigger exothermic electron captures and, possibly, pycnonuclear fusions of light elements that may have been accreted onto the surface from the fallback of supernova debris, from a disk or from the interstellar medium. This scenario bears some resemblance to deep crustal heating in accreting neutron stars, although the matter composition and the thermodynamic conditions are very different. The maximum possible amount of heat that can be released by each reaction and their locations are determined analytically taking int...