Final answer:
Rome officially fought against Macedon for four years during the Third Macedonian War from 171 to 167 BC.
Step-by-step explanation:
The Romans fought against Macedon in several conflicts between 215 and 167 BC. However, the most direct period of warfare occurred during the Third Macedonian War which lasted from 171 BC until 168 BC when Rome defeated King Perseus of Macedon at the Battle of Pydna. After the battle, Rome dissolved the Macedonian monarchy and the region eventually became a Roman province. A lesser-known fact is that Rome fought earlier engagements with Macedon during the Second Punic War when King Philip V of Macedon allied with Carthage against Rome. Ultimately, Rome's victory at the Battle of Cynoscephalae in 196 BC saw Philip become a Roman ally.
Considering significant battles and the duration of the Third Macedonian War, Rome fought against Macedon for four years during the specified period, from 171 to 167 BC. Yet, if we consider Rome's ongoing conflicts with the Hellenistic kingdoms, stemming from alliances and prior engagements, the intermittent strife stretched across many more years.