To be traded past the July 31 deadline, a player must be placed on waivers. This means every team gets a chance to claim him, with the worst team getting priority on up to the best team. If no team claims him (happens often for players with overpriced contracts), then he can be traded to anyone. If one or multiple teams claim him, then only the team with the highest priority, the worst team, can trade for him.
Lots of behind the scenes strategery happens. Teams place tons of players on waivers, just to see who claims them, with no real intention of ever doing anything. Teams will make claims just to block other teams from getting certain players.