I got permanent residence and drove with my EU (issued in Spain) licence (which) I realised was out of date and I'd been driving about for 3 months with an expired licence.
Maybe I was lucky.
Yes, I'd say you were lucky not to have caused an accident (or even been involved in one) while driving with an expired ;license.
If you had been at fault your insurance company might (and probably would) have declined to pay the damages to either party.
Even if the accident was the other driver's fault, his/her insurance company might have used your not having a valid license as an excuse not to pay for damages to you or your vehicle.
And in one or possibly both cases your permanent residency might have been at risk if the police had charged you with a crime.
It's something for all of us who drive to keep in mind.
And it's an example that Dr. Rubilar has used in previous posts about the possibilities of losing permanent residency.
PS: If you had been stopped at a police traffic checkpoint your vehicle would have been impounded on the spot and you would have (at the least) received a multa (ticket) for not having a valid license.
I'm not sure how much all that would have cost, but I'm sure it would not have been cheap.
If you had been involved in an accident (especially one with injuries) you probably would have been arrested and taken straight to jail and your permanent residency would have been in jeopardy.
Depending on the seriousness of the injuries (of others) who knows how long you would have had to spend in jail awaiting trial. Dr. Rublikar previously posted that, as a foreigner, you would not have been released before the trial,
If, at the trial, you were convicted of a serious crime, you would have to complete half the sentence in jail before you could ask to be deported.
In this case it looks like you really had the "Luck of the Irish" going for you.