In 2015 with Solar energy success, the Spanish government implemented RD 900/2015, which includes the "SUN TAX". It consists of a toll for using the main grid.
Actually, the EU has declared this tax illegal. Spanish government should remove it soon in order to be in line with the rest of European countries.
If you decide to install an off grid system, this law does not affect you because all the electricity comes from your own installation.
On grid systems are totally free of paying this tax under 10 KW (a regular house consumes around 4 KW).
So, despite the false beliefs, the "sun tax" does not affect the most of the installations. The use of solar energy is totally legal and free.