Cold: If it's cold, find that ratty sweatshirt/pair of gloves/hat/sweatpants you've been meaning to throw out for years. If you don't have any clothing items ready to be ditched, head to Wal-Mart or a cheap clothing store, and buy some warm clothes you could run in for a mile or two. You can wear these warm items in the corral when you're standing in the cold and have nowhere to move to stay warm. Once you get running past the first mile or two, your body will begin to warm up, and you can shed them. Most marathons pick up discarded clothing at the start and donate them to charity.
Likewise, layers are key while actually running. Remember, you're bound to heat up as the race progresses, so having layers that are easy to remove will allow you to stay cool.
More: Tips for Running in Cold Weather
Heat: There are a lot of strategies you can use when running in the heat. In the interest of brevity, here is a link to a very detailed post of tactics you can implement for running a marathon in the heat.
More: Your Guide to Racing in the Heat
What to do After a Race Goes Wrong
The most important thing you can do after a frustrating race is conduct a post-mortem. Start by making a list of all the possible factors that lead to your disappointing race. For the time being, it doesn't matter if these factors were within your control or not. If you think something may have affected your performance, write it down.
Next, write as many possible solutions or tactics you can implement in your training to prevent these possible hindrances from happening again. For example, if it was hot, you can try training with more layers, or if you had bathroom problems you might want to experiment with a different nutrition strategy in training.
When you're finished, you'll have an extensive list of training tips you can implement during your next training segment and marathon race. You may notice that you have a few factors that you couldn't find ways to improve. These are the factors you can't control (for example, rolled an ankle or the crowds were too large), and sometimes these are just bad luck.
More: How to Evaluate Your Race Season
The important thing with this task is you've taken your mind off the unknown and turned your focus to actionable tips you can implement for next time. Keep this list with you and make sure you look it over before starting your next training cycle. You'll eliminate the same mistakes and increase your chances of having a great race.
More: 3 Marathon Lessons From Olympian Kara Goucher
Sign up for your next marathon.