Long-term behavior of randomly perturbed Hamiltonian systems: large deviations and averaging