It's pretty easy to trap a non-flying forgotten beast. Not inside a trap, but trap it as in it cannot reach any of your dwarves or escape its situation.
The basic idea is that forgotten beasts consider grates and floor hatches pathable, but upon seeing one, they will attack it and destroy it rather than crossing over.
So you create a cell for the thing somewhere, and make a path that connects from where it currently is to the cell where you want it to end up. Then, you block off all passages leading to your dwarves, except for a single path leading from the other end of the cell into the fortress\common area. Then, you channel out 3 floors in the hallway of that 2nd path and remove the ramps from the side that leads to your fortress, and build 3 grates over the path. Once it's complete, have your military retreat through this path over the grates. The cockroach will surely follow. When he reaches the grates, he will destroy them, leaving him no way into your fort. If you're lucky, he will stand still at this point, and if not, he'll quickly run back into the underground to a point where he was standing at an earlier time. Either way, as soon as he's in the room with the grates and destroys the grates, you need to break back into the underground from behind him and seal off the hallway that led into his cell. Now he's trapped in the cell.
Depending how well you engineer the cell and the paths in and out, you can end up with a FB perfectly where you want him by using this knowledge about how they look for a way into your fort and how they interact with grates, hatches, and ledges. A FB that can't fly will consider a ledge without a ramp as impassable and so once he destroys the grate he's screwed.
The problem is you cant know for sure from where the FB or any other underground creature will spawn unless you wall off most of the edges of the map, which is a challenge in itself.
Right now I had a Voracious Cave Crawler kill 3 of my dwarfs because I noticed it too late and it managed to slip through a hole in my defenses and into the main shaft in my fort. Oh the horror.
Before that, a Cave Croc managed to spawn just as the mason was placing the last stone of the wall. That didnt end pretty either.
In other news, a GCS just apeared. Not if only I could bait it into one of my cage traps FBs would be a thing of the past.
Nice, good luck. My last 2 maps I've failed to find any GCS despite seeking relevant factors in my embark. It may be I just need to go down to the third layer. My solution for keeping the underground secure is that I normally penetrate the underground (and the basic soil\rock layers) through a stair shaft in the center of the map. Since it's the only way down I can easily build a wall and\or pavillion and other structures around the staircase to channel invaders. Airlocks using doors, floodgates, or simply placing a block wall on a diagonal pathway are all effective, but FBs can smash doors and floodgates so only the latter is really secure.
The trade-off is that with only one entrance it tends to be less convenient in general, but being able to automatically process any type of forgotten beast into your chosen method of disposal seems quite dwarven to me. If it's a mundane organic creature you simply want dead you could funnel it into a hallway filled with repeatedly-triggering upright spike traps. If it's a flyer or if it's made of indestructible materials and you don't want to capture it, you could send it down a sealed 1-tile hallway with a hollow region carved out above containing a collapse trap on a lever-linked support that causes the overburden to fall and destroy the hallway's contents (you need to place the lever in a common area or lock a dwarf in a room with it to ensure accurate detonation--FBs dont set off pressure plates. Such a trap is also 100% resettable as it works with the collapse of constructed floors and loses only a few pieces each time it's used. If you want to trap the creature, send it down a path that leads it to a grate trap and block it in from behind when it destroys the grate using constructed walls. Once it's trapped like that you can move it anywhere else in the fortress using the same technique you used to trap it originally. I haven't yet thought up a good way to trap a flying FB aside from luring it into a chamber and having building materials and dwarves nearby to instantly seal up the chamber from both sides while it's inside.
As to your problem with being attacked from all over the underground, all I recommend is having a single access point with a diagonal entrance that you can easily wall off from your side, use an emergency burrow to pull your harvesters back inside, seal the entrance and engineer a way to deal with the threat before you give it access to your fort. Use guard dogs on chains in the underground to warn of threats early--when you see a dog get killed, pay attention and deal with the threat. You'll breed plenty more--stop being so sentimental! All of these methods depend on only giving the creature 1 path into your fortress, and if they ever add digging creatures my method is screwed, but dogs are always a solid investment.