You'd need a pathfinding algorithm (such as A*) to find the best route to get there, and to hold at 2 squares away, you'd simply check before the monster took its next move how far away it was.