2003 Grand Am hard to start and periodically dies while driving

There are two issues here. The first is the car has trouble starting sometimes. For example it will start great every time for two or three weeks, then will have trouble starting for a week or two then be fine again. When it has trouble starting it always cranks, has fuel pressure, but won’t start on the first try. It almost always starts on the second try and has never not started. Once it starts it runs fine. The second and more serious problem is the car will just die while driving down the road. No sputtering or anything, it just dies like someone turned the key off. Everytime this has happened (~once every two weeks) it’s been at the first touch of the brake pedal. It will restart, but sometimes on the second try. Like I mention above this happens while driving, not when you first put it in gear. Additonally this problem happens when the car is starting fine and when it isn’t. However both of these issues seem to have come about at the same time. We have taken the car to the dealer three times with no luck. No codes have ever been thrown to the computer. My thought is it could be a bad crankshaft position sensor, but I can’t explain what the brake would have to do with anything. Note: We have had issues with the passlock system, but the security light has never come on around the time of these failures. Any ideas?