I'd buy a SIM in the first country you get to from one of the major carriers. If your first stop is Spain, then maybe get an Orange or Vodafone SIM. Here's some info on the Spanish mobile companies:
Because roaming fees have mostly been eliminated in the EU, you can use the phone for data in all other countries. The trick is being able to top up each month to keep it going after you've left the country, so read the info about each carrier carefully.
I have a Dutch Vodafone SIM I bought on eBay (without going to to the Netherlands to activate it) that I used in Slovenia, Italy, and France last year, and I was able to add credit to it online with a US credit card. However, making calls to other EU numbers may not be included in the plan. Incoming texts are free, though, as are incoming calls I believe (on pretty much all EU SIMs).
You could of course just buy a new SIM after each month in whatever country you happen to be in instead of worrying about topping off the old SIM for another month.