First of all, google for "pathfinding" and in particular "A* search", which is very handy anytime you need things to move around and avoid obstacles.
If you want things to wander randomly, you could try an approach like: pick a random point within a certain radius (excluding points in obstacles) and path to it. When you get there, pick another random point and repeat.
To make them gradually head toward a goal, every few iterations you could substitute the randomly chosen destination with the goal itself, but then only let them travel a short distance before re-randomizing the goal point. Depending on the obstacle geometry there's no guarantee they wouldn't get stuck in a steady state far from the goal, though.