Easiest Method of Sailing
Its probably quite straight forward how a boat can sail in the same direction of the wind. This is done by letting out the boom so that the sails are close to perpendicular to the direction of the wind. When doing this the sails deccelerate the wind, the wind accelerates the sails, and the sails push the boat forward. Not much to it. But you may realize that this method only works if you are going in the same general direction of the wind. So how do sailors navigate around this problem?
Sailing against the wind
There are two ways in which a sailboat can move in the opposite direction of the wind. One is by the the sails changing the direction of the wind to create a thrust. The other is by Bernoulis Principal.

In the first part, while the boat is facing the wind at aproximately a 45 degree angle, the sail is kept straight with the boat and the wind flows into and over the sail where its direction is changed as it follows the shape of the sail. There are three resulting forces: the drag caused by the wind moving over the sails, the lateral force exerted on the sail while the sail changes the direction of the wind, and the final direction and velocity of the air after being redirected. Now the drag between the air and sail is usually low and is usually not considered in the diagram. The two important forces are the final velocity and the change between the initial and final wind velocities, this is however resisted by the boats keel. The keel works against the slower moving water to resist any lateral forces. This is the key component in making a sail boat move against the force of the wind, without it the boat would drift as the wind pushed it.

Bernoulli's Principal
Probably the more important factor in sailing upwind is the effect best explained by Bernoulli's Principal. The sail acts just like an airplane wing. When the wind flows over one side it fills the sail while the air flowing on the other side is moving faster and cannot push as hard and thus the sail recieves a force that is perpindicular to the direction of the wind. This would normally not push the sailboat against the wind but the keel of the boat again resists much of the lateral movement so that the boat has only one direction it can move which is forward, providing that the combined forces that are pushing the boat perpendicular to the wind are greater than the force of the wind pushing the entire boat and sails backwards.

Also note on the diagram that the vectors here are considered forces not velocites. This is important for two reaasons. One is that the drag force will increase as the velocity of the boat increases, when it becomes equal to that of the forward movement it only means that the boat cannot accelerate any further and that is the top speed. Also these forces are relatively independent of speed. The forces do increase as the velocity of the wind increases however the forward movement can become greater than the speed of the wind that is causing the boat to move!

Yes Mag
Go on to Wind and Navigation