The key to buying great shares is to consider their long-term value and not take much notice of their short-term ups and downs — but that doesn’t mean we shouldn’t take advantage of short-term weakness when we see it.

Right now, that seems to be the case with BP (LSE: BP) and Royal Dutch Shell (LSE: RDSB), whose shares look like they’re tracking the oil price — both followed oil down to its recent low of below $42 per barrel, and both have tracked it back up to above $46.

Shares down

Despite the recent mini-recovery, the shares of both oil giants are still down since their recent peaks — BP shares have dropped 6.3% since 12 July, having been down 10.4% on 2 August. Similarly, Shell shares are down 6.8% since 22 July, but that’s better than an 11.3% fall at 3 August.

How should we profit? Other than becoming a stockbroker and earning all those commissions every time a short-termer buys or sells, the answer seems easy to me — buy the shares and keep them for 10 or 20 years or more. The thing is, though today’s oil prices are certainly hurting producers, they really are quite unsustainable in the long run as so much of today’s output comes at production costs that are just not profitable.

We’ve been hearing rumours of plans to stabilise output and boost prices yet again — the latest comes from the Russian energy minister talking about consultations with Saudi Arabia. I don’t see anything having any great effect this year, as we still have a significant oversupply — and some countries, like Iran, are more concerned with ramping up production and raking in some much-needed foreign exchange. But if oil isn’t at least in the $65-$70 range by the end of 2017, I’ll be very surprised — and does anyone doubt that a barrel of oil will sell for a lot more in five or 10 years time?

Coming back to our two big giants, BP and Shell shares are both on forward P/E multiples, based on forecasts for the year to December 2017, of approximately 13.5 — and for two key players in such a vital sector, I really can’t see how that isn’t cheap.

Irresistible cash?

On top of that, we’re looking at two of the best dividends in the FTSE 100, with both on prospective yields of around 7% for this year and next. This year’s predicted payouts won’t be covered by earnings, but cover should be back by 2017 — and neither of them will want to disappoint the City by cutting the cash.

Both BP and Shell released first-half figures last month, and both maintained their interim dividends unchanged. BP’s CFO Brian Gilvary stressed the company’s “confidence in sustaining our dividend going forward.” Shell was more tight lipped, as usual, but surely won’t want to break ranks with a cut.

What was it that BP chief Bob Dudley said when oil was first falling? It was back in January 2015 when he predicted that oil prices could remain low for up to three years, and that’s looking like a canny prediction.

Mr Dudley’s outlook is directed to the long term, and so should ours as investors. And with a longer horizon, I see BP and Shell both as buys now — for share price recoveries in the coming years, and for that delicious 7% per year in cash in the meantime.

Can you make a million?

Should BP and Shell be in your millionaire portfolio? Check out the Fool's 10 Steps To Making A Million In The Market report, which takes you through all you need to know, one step at a time.

What you'll learn, more than anything, is that the secret to long-term financial success is to spend less than you earn, invest your savings in shares, and perhaps most importantly of all... keep a cool head when all around are losing theirs.

What's more, it won't cost you a single penny of your savings to get yourself a copy, so just click here now for your completely free report.

Alan Oscroft has no position in any shares mentioned. The Motley Fool UK has recommended BP and Royal Dutch Shell. We Fools don't all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors.