The .40 round doesn't seem to be as accurate as .45, or so I've heard. My Glock 23 seemed great from the bench! But besides that, .40 is a more powerful round, so there's more recoil. You need to have better follow-through and a better grip in order to make accurate shots.
Another problem, specific to the subcompacts, is that the sights are too close together. Not only does that mean that tiny misalignments give greater errors, but, in the case of Glock sights, you can barely see the space on either side of the front post when trying to align the sights. I find it difficult to align the stock sights on the subcompact.
So how do you fix these issues? For better follow-through, you might have to adjust your shot process. What I do is to look for, and feel for, the trigger stop. That is to say, that when I take a shot, my shot isn't completed until I feel the increased pressure of an immobile trigger on my finger. This act forces me to try to maintain alignment for just a hair longer than I would otherwise. This is so because I'm no longer concerned with the break point, but with the backstop. This causes me to squeeze through the break point smoothly and lets the shot break as more of a surprise. And anything you do that lets you maintain your position while the gun goes through the process of letting off a shot, will improve your follow-through.
As for your grip...grip harder. Don't just squeeze the grip like a tennis racket (which is more like wrapping your hand around the grip)....do it more like trying to squeeze the juice out of a lemon (which is more like pressing the grip into your palm.) The more solidly the gun's grip is against your palm, the more it acts as an extension of your hand.
Also, it seems that a naturally aligning grip is more important with the .40. So practice griping the gun in such a way that the sights are already aligned when you bring the gun up.
As for the sights...change them. But first, try to widen the rear notch with a sharp file. If it doesn't work out then get some quality sights on there, like Heine Slant-Pro or something like that.