Oil Pressure ?

When my car sits at idle for a couple minutes while fully warmed up it suddenly loses oil pressure and the check engine light comes on and then after a couple seconds shuts back off and regains oil pressure. What could be causing this problem? It also rattles a little at cold start ups. Thanks for the help.