I did this 4 years ago now, I'll try to list the key points below, I'd definitely recommend buying a Spanish registered car in the UK then driving it out there as its cheaper the n buying in spain others will say it's to much hassle but I found it pretty easy, the garage I use in Torre Pacheco did all the checks (like hpi or traffic fines as they stay with the vehicle) and documentation of ownership transfer for me.
They key points
Make sure its registered in spain or you'll pay import duty
Get the vehicle registration and check its hpi free and has no fines
All the documentation is with the vehicle including the previous owners nie number (you have to have this)
It has a valid ITV (mot)
It is taxed
Unlike the UK changing the name of the ownership on the logbook costs money in spain hence why second hand car prices are much higher
Most of this can be checked by a garage, the one I use in Torre Pacheco checked all this for me prior to purchasing.
Once I was given the all clear I purchased the car then flew out (I was going over anyway) and gave the garage all the documents to do the name transfer, they need the originals and I wouldn't recommend posting them, if they get lost then you'd have big problems.
It sounds complicated and some will go on about its to much hassle but I found it pretty easy with the help of the garage, and the key point is my vehicle is still worth a lot more in spain 4 years on than I paid for it in the UK, I would of spent double the purchase amount on hire cars in that same period.
Hope this helps
Richard