Yes, you can
The rule on opportunity attacks says (PHB, p. 195; emphasis mine):
In a fight, everyone is constantly watching for enemies to drop their guard. You can rarely move heedlessly past your foes without putting yourself in danger; doing so provokes an opportunity attack. You can make an opportunity attack when a hostile
creature that you can see moves out of your reach.
So the only condition is that you have to be able to see the creature, and that it moves out of your reach (normally, 5 feet). The rule even talks about not being able to move past other creatures without risk.
The game does not have "engaged with another creature" as a formal game term. In melee combat the danger of being right next to an opponent is expressed by imposing disadvantage on ranged attacks when a foe is within 5 feet of you, or Sneak Attack triggering if an opponent is threatened by someone within 5 feet of them, but it does not put any limitations on opportunity attacks. Even if you are grappling another creature, all you need is the use of one of your hands. You could still make opportunity attacks with your other hand against a creature that moved by and left your reach. You are not exclusively engaged with someone you fight in melee, a lot can happen during the chaotic action of a combat round.
Moving into your reach does not normally trigger opportunity attacks in 5e; unless you have a specific feat that says so, like Polearm Master, the game only cares about moving out of your reach.