Yes and no.
There are min. energy requirements for all new builds, compulsory from 2006 (licences from 2007) and don’t forget that there are 12 climate zones within Spain.
Existing buildings only have to comply if they are being substantially reformed.
None of this is mandatory for either selling or renting.
Each autonomous community has jurisdiction over and regulates the inspection/certification system.
Suggest you get hold of the CTE Documento Basico HE “Ahorro de Energia”.