The magnetostatic energy of a two-dimensional (2D) periodic array of magnetic particles (or a thin film with periodic magnetization) is evaluated, including additional energy terms due to a polarizable substrate. The polarization of the substrate is solved self-consistently using surface charges. This requires describing the magnetic potential of the 2D array in terms of an equivalent surface charge distribution. Analytic expressions for the magnetostatic self-energy of the 2D array as well as the energy due to the interaction of the magnetic structure and polarizable substrate are presented. It is shown how substrates with large susceptibility significantly alter the stray-field energy and, hence, the magnetic properties of the array, even promoting a spin-reorientation transition. Our results suggest that system properties can be controlled in a simple way by exploiting substrates with tunable polarizability.