Theory of inertial spin dynamics in anisotropic ferromagnets