A ball is said to be in play when the fielders can attempt to make a play to retire a member of the batting team. A ball that goes "out of play" is a dead ball and runners cannot be put out if any advance is required as a result, unless they fail to touch a base during such advance.
All fair balls are in play, except for home runs once they cross over the fence, when they become out of play. Thus, the famous play made by Bugs Bunny in which he hires a cab to drive out of the stadium and catch a ball miles from where it was hit would not stand under major league rules...
Foul balls are in play as long as they do not leave the portion of foul territory located within the confines of the field of play. Thus fly balls hit in the area between the first base foul line and the dugout, for example, are in play and can be caught. However, balls hit into the stands are out of play. Ground rules will determine how balls are treated in areas of the ballpark where the demarcation between the field and the out-of-play area is not clear. A fielder can catch a ball hit into an out-of-play area as long as he remains in-play himself; if he leaps and falls with the ball into the stands, or on the other side of the fence, the ball is considered to have been caught, but it is a dead ball and every baserunner is allowed to advance one base. If he is standing out of play when making the catch, no out is recorded.
This also applies to balls which wander off as the result of a wild pitch, passed ball or throwing error. The umpires will let baserunners advance two bases from where they were standing when the errant throw was made if such a situation occurs. For example, if the shortstop airmails a throw into the stands while trying to throw out the batter-runner at first, the umpires will place him on second base (he gains both first base and second base on the play); if he had already rounded first base when the throw was made, he would be placed on third base.
Chapter five of the official rules deals with balls in play and out of play, and live and dead balls.