Long-range contributions to the total energy of an impurity in an extended substrate