Catalysis of the reaction: (S)-3-hydroxyacyl-CoA + NAD(P)+ = 3-oxoacyl-CoA + NAD(P)H + H+, where the acyl group is a long-chain fatty acid residue. A long-chain fatty acid is a fatty acid with a chain length between C13 and C22.