The successful reestablishment of an independent Portugal in 1640-68 was in many respects a matter of timing. Portugal's position within the Spanish empire was a highly anomalous one and although the Castilian crown controlled foreign policy and other executive functions, Portuguese elites retained a number of privileges and sway over domestic and colonial affairs. This relative independence helped incubate a growing dissatisfaction with Habsburg rule among the Portuguese elite. Olivares's proposed Union of Arms increased the tax burden and threatened to undercut Portugal's relative independence by reorientating the empire into a more centralized direction. The Habsburg's inability to retake Brazil from the Dutch also exacerbated tensions as Brazil was Portugal's most profitable colonial enterprise. This simmering discontent provided kindling for any pretext to throw off Spanish authority.
The war with France and the expansion of the war in the Mediterranean created just such an opportunity for a successful Portuguese revolt. The crux of Olivares's strategy was maintaining Spain's loose connections of Italian and Central European/Low Country territory called the Spanish Road. The Catalan Revolt, also brought about by higher taxation and the Union of Arms threatening of traditional privileges, made the quashing of this revolt a strategic priority for Madrid. The military logic was that Catalonia could provide the French a gateway to the southern half of the Iberian peninsula and cut Spain off from its highly trained armies in the Low Countries and its Italian dominions. Thus when faced with the dilemma of invading either Portugal or Catalonia in 1640, the Habsburgs opted for the latter as their armed forces in the Peninsula were incapable of doing both simultaneously. This gave the Portuguese rebels time to fortify key strategic areas within the frontier. This meant when Spain had mustered troops to invade in the early 1660s, they found themselves conducting costly sieges that could be countered by the new Portuguese armies. Portugal's climate and geography also greatly helped as Spring rainy season, hot summers, and the onset of winter snows typically limited the campaigning season to early summer and early autumn. The mountainous geography channeled large armies down certain directions and helped prevent the Spanish from achieving surprise. The preoccupation and eventual defeat of Spanish naval power in the Low Countries also played a role as it denied the Spanish forces the naval logistical support that had been vital for Alba's successful invasion of Portugal two generations before in 1580.
Olivares recognized that time was on Portugal's side when the revolt had broken out in 1641. In 1641 Consulta, he noted:
each day's delay makes the enterprise more difficult because of the abnormality of wanting to wait until an experienced army is raised; it follows that, in the meantime, before it is amassed, the enemy will build fortifications and will arrange the provision of everything he now lacks, so by delaying, he will have all that he needs; delay is the greatest enemy.
The problem for Olivares was that although he recognized this danger, he lacked the effective means to counter Portugal's revolt. The few Spanish resources in the Iberian peninsula had to be used to counter France, which was a greater strategic threat. This meant the squashing the Catalan Revolt took greater strategic priority than restoring the Iberian Union.
Sources
Elliott, J. H. The Count-Duke of Olivares: The Statesman in an Age of Decline. New Haven: Yale University Press, 1986.
Parker, Geoffrey. The Army of Flanders and the Spanish Road, 1567-1659: The Logistics of Spanish Victory and Defeat in the Low Countries' Wars. Cambridge [u.a.]: Univ. Press, 2004.
White, Lorraine. "Strategic Geography and the Spanish Habsburg Monarchy's Failure to Recover Portugal, 1640-1668." The Journal of Military History 71, no. 2 (2007): 373-409.