Lattice dynamics and ultrafast energy flow between electrons, spins, and phonons in a 3d ferromagnet