Constrained Monte Carlo method and calculation of the temperature dependence of magnetic anisotropy