Oil is at its lowest price level since 2003, and, if you're like me, the energy stocks in your portfolio have taken a beating. However, by employing some of the principles of the most successful investor of all time, you can use this as an opportunity to set yourself up for the long term. Here are three Warren Buffett rules that can help you turn this seemingly awful time for energy stocks into your finest hour.

Whatever you do, don't panic
The absolute worst thing you can do when times get tough is to panic and sell your stocks. As Buffett has said, "Be fearful when others are greedy, and greedy when others are fearful." In the energy sector, investors are definitely being fearful right now.

Warren Buffett's Berkshire Hathaway (BRK.B -0.69%) (BRK.A -0.76%) has produced average returns of 21.6% per year over the past 50 years, while the average investor garnered about 2% over the past 30. What's the difference? Easy -- the average investor gets nervous when prices fall and sells at a loss. And, when they see everyone else making money on "it" stocks like Tesla and Amazon.com, they buy when prices are already high. In other words, common sense tells us that the goal of investing is to buy low and sell high, but many investors do the exact opposite.

The best thing you can do is to think of this oil crash as an opportunity to buy quality companies on sale. Instead of panicking because a stock for an excellent company is down 25%, try to think of it as being on sale for 25% off.

It's important to note that this only applies to stocks you still believe in for the long run. If the reasons you bought the stock in the first place still apply (good value, unique products, etc.), hang on or add to your position. On the other hand, if something has fundamentally changed since you bought, it can be a good idea to re-evaluate your investment.

Look for a wide moat
A "wide moat" refers to a sustainable competitive advantage that makes a company more likely than its peers to be a long-term success. This can mean several things. For example, a strong and recognizable brand name gives a company pricing power. A superior credit profile allows a company to borrow money more cheaply than everyone else. Superior management, unique products, and lower overhead are also examples.

In the energy sector, there are several examples of wide-moat stocks trading for a discount. Take ExxonMobil (XOM -2.78%). Not only is Exxon the largest and most diverse U.S. oil company, but the company has an AAA credit rating -- even better than the U.S. government. This allows Exxon not only the financial flexibility to make it through the tough times, but gives it access to cheap borrowing for acquisitions and other investment opportunities. In addition, certain aspects of Exxon's business, such as refining, actually become more profitable with cheap oil.

Another good example is National Oilwell Varco (NOV -0.42%), which admittedly, is a stock Buffett sold in 2015. The company sells equipment and technology to the oil drilling industry, and the share price has understandably fallen along with drilling activity. However, National Oilwell Varco is dominant at what it does. Its market share of offshore drilling rig equipment is more than 80%, and its standardized rig designs make the company the source for spare parts.

Buffett has said, "It's far better to buy a wonderful company at a fair price than a fair company at a wonderful price." Identifying wide-moat stocks can help you find those wonderful companies.

Find a margin of safety
In broad terms, a margin of safety means buying a stock for less than its intrinsic value, and is the central idea behind value investing.

In practice, this can take on several different forms, as there are many ways to determine how much a stock is actually worth. One simple way of finding a margin of safety is to find businesses that trade for less than the value of their assets (book value).

As an example, National Oilwell Varco trades for just 61% of its book value as of this writing. This means that you are paying $0.61 per $1.00 worth of assets on the company's balance sheet. The idea behind this is that even if the share price falls further, you'll still be buying the business at a "discount."

But wait! Couldn't oil prices keep falling?
Of course they could. While I don't think oil will ever get into the sub-$20 range, the past year has proven me wrong several times about what the price of oil can't do. It's entirely possible that you'll buy ExxonMobil for $77.50 today and the share price will be $70 next month.

If this happens, it's important to remember to stick to the game plan. Buy even more of the long-term winners that you believe are great in the sector at an even cheaper price, and be prepared to hold your shares for years to come. You won't get rich overnight, but getting into a habit of ignoring market noise and finding long-term winners at cheap prices can build tremendous wealth over time.