The key to defeating a Greek or Macedonian Phalanx is usually exploiting its lack of mobility. The romans understood this very well, having learnt the lessons themselves during the Samnite Wars.
A Phalanx is a very strong formation in any one direction so long as it retains unit cohesion. It can present a nearly inpenetrable wall of shields and bistling spears capable of destroying just about anything in front of it. The trade-off here is that while it is extremely strong in the front, it is very inflexible and vulnerable in any other direction. It also relies heavily on maintaining formation.
By contrast a Roman legion employs a manipular system that is far more flexible. On even ground, in a head to head confrontation, a legion would likely be worn down by a phalanx formation (or at the very least trade relatively unfavourably). The romans knew this very well. They themselves had been the inflexible ones in the early phases of the Samnite wars and paid the price for it (at Lautulae and Caudine Forks for example).
At battles such as Pydna and Cynoscephalae we see roman formations engaging phalanx formations in uneven terrain. At Cynoscephalae the Romans and Macedonians engaged in hills and even thought the Macedonians held the higher ground, they were unable to maintain formation in the rough terrain. At Pydna they met on relatively even ground only to see the Romans fall back into uneven terrain (a prepared tactic). Again the Phalanx was unable to maintain formation and in both cases it was soundly defeated.
In a broader context, the Roman "conquest" of the Hellenistic armies was partly due to their ability to deal with phalanxes but also due to the sheer speed of the conquest. There simply wasn't time for the greeks to reform their armies even if they had wanted to.
100 Decisive Battles from Ancient Times to the Present: The World’s Major Battles and How They Shaped History - Davis, Paul K.
Greek & Roman Warfare: Battles, Tactics, and Trickery - Montagu, John D.
Two battles provide ways into how the Roman army beat Phalanx/pikemen centered armies; the Battle of Cynoscephalae and the Battle of Magnesia.
The number one tactic? Probability the mobility of the legion. The phalanx, as with any infantry block, is vulnerable from the sides and back, but unlike the Romans, could not turn and cover the flanks. In the Battle of Cynoscephalae, half the Macedonian pike formation pushed back the Romans such that the army got separated into 2, with half keeping pushing back the Romans, the other half still engaged. Wikipedia has some nice graphs which show the order of the battle. Phalanxes are very very vulnerable in the flanks, and it's quite easy to do so, especially if the enemy has insufficient cavalry. Pikemen are dangerous only from the front, so opposing armies favoured flanking maneuvers.
That was battlefield movement, but on the battlefield itself, the individual Roman soldier had advantages. The pilum, a javelin, could be thrown, and due to the 2 handed sarissas of the Macedonian phalanx, could not be countered with shields. In fact, pike blocks were very vulnerable to all sorts of missiles. Roman shields were also more protective, being rectangular while Macedonian shields for pikemen could not be used as effectively as both hands had to be holding the pike.