WHat you will need is a student visa. With that you can work part-time. Check with the school you will be getting certified with to see if you can apply for a student visa through them. Otherwise, what I did was apply to a language academy where I studied Spanish a few hours each day. Through them I got my visa. Your student visa must be obtained here in the U.S. Once you have that, you can legally stay in Spain as long as you are enrolled in language courses. Also, every 4 or 5 years Spain has an amnesty that allows illegals to become legal IF they have a job offer. The last one was in ‘05, so the next one will be coming up soon I would imagine. If you’re there for that and have a job offer, then you can apply and you will no longer need to work on a student visa or go to school. You wil be allowed to work full-time.
Hope this helps. Good luck!