When you are ´de baja´ for medical reasons, your entitlement to paid holiday days will continue to grow, as if you were working.
If you had planned a holiday, but fall ill before or during, the days you were on sick leave will not be taken off your entitlement (except for the first three days if it´s in your contract that these will be taken from your holiday entitlement, instead of just not being paid).
If you continue to be on sickleave on December 31st of any given year, and thus have not been able to take all your holidays corresponding to that calendar year before the year was up, they should be forwarded to the next. Maximum window is 18 months after the calendar year in which the entitlement was built up. As stated in article 38 of the Statute for Employees.
EXAMPLE. If you had a holiday planned for December 2016, 15 days, but you fell ill after the first week, so had 10 days of that entitlement left and you were still on sickleave on December 31st, those 10 days (and any other you had left) should be forwarded to 2017. If you were on sickleave all through 2017 as well and even a couple of months into 2018, on receiving the ´alta´say in March 2018 you will still have your holiday entitlement of 2016 AND 2017 plus part of 2018 as still no 18 months have passed since 31.12.2016
What happens with any left holidays if I´m on sickleave and my contract ends?
If your (temporary) contract ends while you are ´de baja´ for common illness, the holidays you have not been able to take, should be paid out by your employer. But only when no more than 18 months have passed since the year those those holidays pertained to.
Can I take a holiday while on sickleave?
In some circumstances, if the holiday would be beneficial for your recovery, but you have to ask for permission from the Seguridad Social first.
Can I take a holiday straight after receiving the ´alta´?
Yes you can, if you had your holiday planned for the month of July, even if you were on sick leave until June 30th and then were given the ´alta´, so declared fit to return to work, you can go on holiday on July 1st, as planned.
More info in THIS ARTICLE in Spanish.