The following answer will assume that you are trying to do the following:
There are certain tiles in your background which already have shadows baked into their images. You don't want your shadowing layer to affect them at all, but you do want your shadowing layer to affect everything else.
There are several ways to accomplish this.
No "foreground layer" at all. Instead, have each tile tell whether it is shadowed or not. Render the non-shadowed tiles as normal. The shadowed tiles are rendered with two textures and two texture coordinates: one that picks from the background texture atlas (or however you're doing your rendering) and one that picks from the foreground atlas. You simply do the "layering" as part of your shader/texture environment. It's a simple multiplication, or perhaps an alpha blend, depending on how your shadowing works.
The same goes for sprites.
This method only works on a per-tile granularity.
You can employ a stencil buffer (if you do, make sure you also have a depth buffer. 24/8 depth/stencil in size). This brings layering back, but you still need to mark which background tiles need to be shadowed and which ones don't.
At the beginning of the frame, clear the color, depth, and stencil buffers. The stencil buffer should be cleared to 0.
Tiles that do not need shadows should be rendered with a stencil value of 0. Tiles and sprites that need them should be rendered with a stencil of 1. Make sure that your sprites use alpha tests/discards to cut out the area around them.
The code for this would be (warning: untested):
//Change the second parameter to 0x01 for objects that should be shadowed.
glStencilFunc(GL_ALWAYS, 0x00, 0x01);
glStencilOp(GL_NEVER, GL_REPLACE, GL_REPLACE);
When you draw your shadowing layer, what you do is turn on the stencil test and have the test function be equals. All of your foreground should be rendered with a stencil value of 1. The code you would use before rendering your shadowing layer would be (warning: untested):
glStencilFunc(GL_EQUAL, 0x01, 0x01);
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
Again, this has a per-tile granularity.