Environmental effects on quantum relaxation and coherent dynamics in rare-earths ions