The answer to this question is different if you are going on a long-distance tour rather than going-to-work-and-back.
If on tour and facing the prospect of a struggle to do 30 miles when you really wanted to get 100 miles in (e.g. to get to next camp-site) it can be a better idea to not bother, sit out the wind and have a go later that day/evening or the next day.
It is also important to understand weather a little bit.
The air in a valley will heat up on a sunny day and, as that air expands, it has to go somewhere.
This can lead to a tough headwind instead of an easy down-hill ride when going into the valley.
This process works in reverse, so, if planning a long distance ride and crossing valley systems it can be best to book a room in the town at the bottom of the valley rather than pitch a camp at the campsite near the top of the mountain pass.
Weather generally is more active during the day than at night so the best times for avoiding wind in a known windy place are early mornings and night.
Clearly this does not help if you are doing 9-5 but if you are doing other shift patterns then you might be able to choose your shifts so as to get a near-guaranteed tailwind in both directions, to work and to home.
If you have to ride into headwinds there are a few things you can do: Think of wind as water and imagine where the 'river of wind' is going to be slowest.
in the middle of the road the wind will not be slowed down, by the edges it will be slower, albeit marginally.
Hence, try to ride safe-yet-close to available fences and walls.
in that way you will 'not be swept away by the current'.
The sea also has an effect on wind - if following a coastal route try to find a route further inland.
The sea heats up differently to the land, this will have seasonal affects on prevailing wind direction.
Also bear in mind that most winds are from the west due to the turning of the planet.
Try to be as aero as possible - keep your elbows in.
it may not be full-aero-tuck, but, elbows in will make a difference to your overall drag.
You can also hold your handlebars a bit more in-board than you would do otherwise.
Roll with the punches.
If there is a gust of wind that is going to stop you in your tracks then you can ease up and put your pedal effort in when the gust has passed by.
Make sure you are not wearing a big balloon.
A skirt or a coat can act like a giant parachute - not what you need.
Much like how a parachute has a hole in the top to let the air out without undue turbulent effects, make sure your coat has an exit hole for the air driven in through the front.
Be seated.
When out of the saddle you present a bigger frontal area.
Use your gears rather than getting out of the saddle to get your momentum up.
Sit low.
Tiredness helps to 'fall over the bars' and have a flat back.
Pretend you have been riding all day and adopt the flattened pose that you get then, with your legs spinning and your upper body relaxed.
Draft anything you can - other cyclists, motor vehicles such as buses pulling out can give small bits of aero benefit.
If the problem is persistent on your route consider getting a 20" wheel folding bike.
This will have better aerodynamics than your MTB/hybrid, you can also fold it up and take the bus/train as far as you can towards your destination.
Also consider a saddlebag rather than a rucksack/panniers as saddlebags are the most aero bag option.
If the headwinds are always against you and your job matters more than your home, consider moving to the other side of town so your commute is with the prevailing winds rather than against them.
bicycles.stackexchange.com/users/1487/ʍǝɥʇɐɯ
I deal with this at least once a week.
Yesterday I was going 18km and hour with a heart rate of 175bpm (normally that's 35+
).
I get on the drops on my bar to reduce my wind profile.
I try to stay on less busy streets (normally I'm out in the farm area) because the side gusts will cause swerving.
Pay very close attention to what's behind you b/c of swerving.
Get in an easy gear and spin it out.
Head winds are great 'hill like' training.
Don't ever get a disc wheel since the added surface area will just make it worse in cross-winds.
bicycles.stackexchange.com/users/30/curtismchale
Some suggestions: Stay in lower gears and cycle at a higher cadence .
Using lower gear will help you to maintain momentum when hit by gust full on, and to retain control when hit by crosswind gust.
Keep a low profile Avoid baggy clothes
Find a cycling partner and share
slip streaming
bicycles.stackexchange.com/users/73/Kevin
I do my best to tack.
Kind of like a sail boat.
For example If I'm riding in the city and the winds are from the south I'll ride a mile or so south and then head east for a block or so to catch a break, head south for a mile or so and then head west a bit to catch a break.
It sure lengthens the ride but it can be good to get the short recovery periods.
If it's on bike paths or trails
I just stay low and grind it out.
bicycles.stackexchange.com/users/9/Mike Two
Perhaps a bit drastic, but I've found wind much less of a problem after moving to a recumbent (for obvious reasons).
bicycles.stackexchange.com/users/128/Tom Hawtin - tackline
One approach is to just accept that you won't be able to ride as fast as in still air and slow down a bit!
Its certainly more enjoyable than battling hard against a head wind, especially if you aren't feeling so good and not in a hurry.
This, as well as some other tips, are included in this article: http://roadcyclinguk.com/how-to/technique/six-ways-to-bear-a-headwind.html
bicycles.stackexchange.com/users/1582/Andy
I happen to live in a windy climate. I often find myself riding against strong headwinds and sudden gusts seemingly coming from all directions at once.  What are your tactics for riding in such conditions?
Tactics for riding in strong winds
bicycles.stackexchange.com
<weather><wind>
bicycles.stackexchange.com/questions/347
bicycles.stackexchange.com/users/122/Tadeusz A. Kadłubowski
Probably the best solution to strong winds is to wait until they calm down. However, if cycling is necessary there are a few tips to follow to stay safe. Keeping a low profile and avoid baggy clothing to reduce drag. Staying in a low gear and pedalling faster helps to avoid being stalled by a sudden wind. Keeping away from busy streets helps avoid accidents caused by being knocked off course.  If the commute is not necessary, you might want to wait for the wind to subside. If it is, a strategy for driving in such weather conditions would be to visualize the wind and adjust your cycling accordingly. Try to minimize your exposure to the wind, keep away from gusts in busy streets, keep your head low, wear appropriate clothing and tack. In technical terms, lower gears and a higher cadence will help stabilize you against the wind. You could also use an alternative vehicle that is better for such conditions, such as a recumbent. From a psychological perspective, you should accept that your ride will take longer. 
If the commute is not necessary, you might want to wait for the wind to subside. A strategy for driving in such weather conditions would be to visualize the wind and adjust your cycling accordingly. Try minimizing your exposure to the wind, keep away from gusts in busy streets, keep your head low, wear appropriate clothing and tack. You could use an alternative vehicle that is better for such conditions, such as a recumbent. From a psychological perspective, you should accept that your ride will take longer. In technical terms, lower gears and a higher cadence will help stabilize you against the wind.