A major power outage has hit large areas of Spain and Portugal, affecting key cities such as Madrid and Lisbon.