Cohen-Macaulayness with respect to Serre classes