Local optimality of cubic lattices for interaction energies