Permanently? It would take quite a lot of changes. Personally, I think that I'll be splitting hairs here, but Spain as a Great Power in a situation where it better reforms relations with its successor states in the New World is quite reminiscent of Great Britain in OTL. And, even with Portugal included in Spain, that power will later shift to the Americas, with Spain losing its position to either the future Mexico or Brazil as head of such a Latin Union.
What type of Great Power, quote unquote, is Spain desired to be? A world-wide Commonwealth of like-minded successor states through which it exerts soft power? A densely-populated, highly-advanced, innovative state which would be the source of a large amount of culture and technology? Or are we talking about a large, populous state which is the leader of an alliance bloc and has a large amount of territory and natural resources to which fuels its power?
I think if we want Spain proper to maintain itself as a great power, it would have build up its infrastructure and channel its energies to the expansion of Spain proper. That would be the key here; we're not talking about expanding its possessions.
Honestly, I think the best way, and most obviously, would be to accelerate the Reconquista and have it continue across to North Africa. I'm not sure of the rate of conversion inside of Muslim Iberia, but I'm sure that a quicker reconquest would mean there would have been fewer converts in general, and that there would be fewer Moors that would end up being expelled. And, if the support is there in Spain, and there are few threats to the North (infighting in France or battles with England over the crown or conflict with the HRE) they could proceed across the channel and start expanding their territory. That might lead to the strengthening of the Subsaharan states or Egypt if the natives continue to flee the Spanish, which would have interesting effects later on.
That might eventually lead to the Spanish (for simplicity's sake, instead of differentiating over which Crown might eventually lead a United Iberia if it happens) eventually establishing control over a large portion of North Africa before being stopped by either a Muslim power or troubles to the North. Continued resource and wealth is extracted from the New World colonies and is used to improve Spain and its European Holdings, and over the decades and centuries that might eventually include North Africa. And, as the state grows fat, it might look towards the Levant, and a reconquest of Jerusalem as it duels with the Ottomans (or equivalent) for control of Africa and the Mediterranean.
Keep Spain out of any Thirty Years War or equivalent, and keep its wealth from being spent on anything but the improvement of Spain. Don't let it be inherited by the Hapsburgs or any other power. Keep its neighbors weak and its own economy strong.
This may mean we have a Spain far different than OTL, but I just don't see a Spain in a Latin Union being Spain as much as Great Britain retaining its possession of North America being Great Britain. The power and center of government will eventually shift west. That is fine if that's what you want to accomplish, but I fear that it would cease to be Spain, which invalidates the whole purpose of the OP.