Three-loop formula for quark and gluon contributions to the QCD trace anomaly