We investigate synchronization in networks of Kuramoto oscillators with inertia. More specifically, we introduce a rewiring algorithm consisting basically in a hill climb scheme in which the edges of the network are swapped in order to enhance its synchronization capacity. We show that the the synchrony-optimized networks generated by our algorithm have some interesting topological and dynamical properties. In particular, they typically exhibit an anticipation of the synchronization onset and are more robust against certain types of perturbations. We consider synthetic random networks and also a network with a topology based in an approximated model of the (high voltage) power grid of Spain, since networks of Kuramoto oscillators with inertia have been used recently as simplified models for power grids, for which synchronization is obviously a crucial issue. Despite the extreme simplifications adopted in these models, our results, among others recently obtained in the literature, may provide interesting principles to guide the future growth and development of real-world grids, specially in the case of a change of the current paradigm of centralized towards distributed generation power grids.