Derivation of interionic potentials using embedded quantum-mechanical clusters: Cation and anion impurities in MgO