Joint formation of quasars and spheroids. II. The Chemistry