Energy-energy correlations to second order in quantum chromodynamics