That being said, if you want a united Iberia to work, then the 1580 union isn't a very good starting point to begin with. By 1580 the national consciousness and overall trajectories of Spain and Portugal had already been clearly defined - the War of the Castilian Succession, the Treaty of Alcáçovas, and the Treaty of Tordesillas had all neatly delineated the long term interests of the Avis realm of Portugal and the Trastámara realm of Castile-Aragon. The growing feelings of cultural and national estrangement between these two kingdoms would be further accentuated by their individual points of pride: the conquest of Mexico and Peru or the discovery of India and China were considered Castilian or Portuguese accomplishments, respectively, not Iberian or Spanish ones. Another factor was the Habsburg inheritance of Castile-Aragon - the Habsburgs were, after all, a dynasty of foreign extraction that had not taken part in the Reconquista, the defining Iberian cultural experience - and it took a few generations for even the Castilians and Aragonese to begin to consider their Habsburg rulers as truly Spanish. By 1580, the Castilian-Portuguese rivalry is already cemented, with the two no longer viewing each other merely as fellow Iberians, but as untrustworthy foreigners with adverse designs on one another. One can see this rivalry play out with all its disastrous effects in the East Indies, where the Castilians and Portuguese were exceedingly reluctant to offer each other assistance, resulting in the Dutch essentially making off with the greater part of the Portuguese maritime empire.
A lasting and relatively stable Iberian Union therefore needs a few things:
1 - A native dynasty: No entanglement in expensive and futile European affairs, more focus on the wants and needs of Iberians. The best scenario would possibly be an Avis ascendancy, so that the Portuguese fears of Castilian dominance are at least offset (for a while) by having their own monarch in charge.
2 - An earlier union: Preferably before the Age of Discovery really kicks off, so that the conquest of the Americas or discovery of the Far East are treated more as "Look what we Castilians/Portuguese have done for Spain" and not so much as "Look what we've done for Spain/Portugal"
3 - A common cause: The experiences of the Reconquista have already done a good job of developing feelings of kinship amongst the Christian Iberians, so continuing this trend (with North Africa or the Ottomans as the target/enemy) will at least maintain a sense of camaraderie through shared struggle. It's also important that the members of the Iberian Union want to remain united, either out of unwillingness to terminate useful relationships or out of fear at the thought of going it alone (the Portuguese profiting from Castilian aid in the East Indies while the Castilians and Aragonese profit from Portuguese rearguard action against the Ottomans in the Indian Ocean, for example).
4 - Ties of blood: This was an idea of the Count-Duke of Olivares, being the encouragement of intermarriage between the different Iberian kingdoms and, more importantly, between their nobles. A powerful aristocratic family with holdings in two or more of the Iberian kingdoms is not going to want to see those kingdoms severed.
5 - A federal approach to governance. Let the Castilians be Castilian, the Portuguese be Portuguese, the Catalans be Catalan, the Basques be Basque, etc. Having a shared language and legal system is great, but it would be much more prudent to have such things develop more organically than to try to enforce them through a massive Bourbon-esque overhaul which injudiciously favors a specific group of people. Don't try to force Castilians or Portuguese into one another's colonies, allow them instead to request one another's presence once they realize they need each other's resources (the Portuguese would benefit from Castilian manpower and the Castilians would benefit from the assistance of the Portuguese navy).