Let's start with the fact that it is not just, on the other hand, if you are completely satisfied with the situation of illegal immigrant, you can leave at any time, but to find a job will be almost impossible.
But to legally stay in the country there are a few basic options.
The first option is to get married) in/in European/E.
The second option is to obtain a job offer from local employer.
The third option – the restoration of the family. To do this you must be officially recorded (registered) relative the first or second line, which by birth is a citizen of Spain.
The fourth option is the business. Don't think that you can come to Spain and open, for example, a shop or a café, the representative of non-European States make this impossible. But you can be the owner of the business (in this case the Manager must be a person with a European passport), and after several years of work with all taxes the Manager will be able to issue you an invitation to the country on the basis of works related to the work.
The fifth option is to live at least three years from illegal (only if they have local Hukou), and then submit documents on the settlement. However, this option is not the best, because now the number of refusals on this basis has greatly increased, and the laws are changed and not the best for migrant side.
Suggest to start with learning Spanish, without this your chances are practically zero, because the English almost did not say. To stay in the country if you have your own finances will fit the entry level, and in order to to work required average conversational level of proficiency.