I got a Ph.D. admission as an international student from Madrid University. As an Iranian, if I got admission from another country other than Spain I would choose to stay there too because of the horrible condition of my own country. I know about the rules and regulations in countries such as Canada or The United States, but I do not know if it is possible to stay in Spain after graduation and seek permanent residency. My field of study is business and management.
Yes, in general it should be possible, the most straightforward way is to be employed in highly skilled work, with this you would be able to obtain an EU Blue Card, from where a reduced period is required to apply for permanent residency (around 2 years).
You would definitely benefit from learning Spanish at least to the A2/B1 level.
Also note that moving inside the Schengen area is easy, if you find skilled work in another EU country, you can apply for a new visa in Spain and then directly move to your new EU country, there is no need to go back to your country of citizenship for this.