Stormtroopers are not poor soldiers. Let's consider the situations in which they find themselves:
A New Hope: Stormtroopers led by Vader seize a Blockade Runner, suffering some losses. Soldiers on Tatooine are susceptible to Force Persuasion, and are slow to break out the big guns to stop a freighter from escaping. Stormtroopers on the Death Star show poor accuracy and tactics during their pursuit of the main cast. Many seem to be killed or wounded, and very few even come CLOSE to hitting the good guys.
Empire Strikes Back: Snowtroopers overrun prepared defenses at the Rebel base. The Rebels are routed and flee. Later, Stormtroopers escort Vader on Cloud City, essentially do nothing...except for completely (and virtually invisibly) taking over the entire security.
Return of the Jedi: Storm and Scout troopers guard the forest moon of Endor. A covert strike team supported by the indigenous peoples of the moon assault the base and destroy it.
Taking these in order, then:
ANH: During the boarding action at the start of the movie, the stormtroopers assault a ship. Despite the defenders using cover and being aware of their entry point, they suffer only minor losses and quickly seize control of the ship.
The stormtroopers on Tatooine are most likely part of the local constabulary, not regular army units - their training is sub-par, they have gotten into a routine, and they are trying to add additional duties on top of their standard ones - they're expected to monitor traffic into and out of a city the size of Mos Eisley. When it does all hit the fan, they respond with respectable speed to uncertain information (a single non-human informant, who likely was paid well for his trouble).
After the Death Star escape, Leia says it herself:
"It was too easy. They let us get away."
The stormtroopers harried the main cast during their entire retreat to the ship. They continued operating under their orders (including the order to not kill the pilot or princess, to ensure that they escaped to the Rebel base) even while taking casualties. At one point in the chase, after Luke sees Obi-wan struck down, stormtroopers are seen carefully aiming, and each shot misses, even as they are picked off. They show remarkable devotion to their duty by staying cool under fire, shooting to miss, and ignoring their natural desires for vengeance against the ones who are hurting their friends and colleagues.
ESB: Nothing to see, here. Stormtroopers doing what they do. They assault and overrun fixed, prepared defenses with such speed that they are able to cut off the internal security and overrun the base far quicker than the Rebels expected. They do this DESPITE the way their heavy artillery is hampered by the Rebel air forces.
Later, at Cloud City on Bespin, they seized control to the point where normal operations were not interrupted, the common persons had no idea of their presence, and maintained it. As pointed out by Mark in the comments, they did this with virtually NO prep time. So being able to flawlessly seize control of what is effectively a space station (best parallel I can come up with, despite it being technically in atmosphere), and hold it effectively indefinitely, maintain discretion even after inadvertent discovery is an application of their standard training, since they were able to do it from a standing start.
RotJ: This is the situation where the stormtroopers are worst portrayed. In the jungle, they are unable to prevent the destruction of the shield generator.
Their loss, however, is mitigated by several factors, many of which can be traced back to the Emperor himself:
- They aren't issued proper equipment
for their surroundings. They have
shining white armor in a jungle.
- They do not properly prepare their
defenses - there are no 'kill zones'
around the base itself, which any
military would prepare in an area of
- They are forced to
allow the covert group to initially
succeed, while the Emperor works on
Now let's consider their opposition: the Ewoks. Yes, they seem silly. They're tiny little teddy bears, they were created for marketing purposes, and not nearly enough of them were shown dying. But from an in-universe perspective, really think about what we see. These little, curious, cute fuzzballs are completely psychotic. They volunteer in HUGE numbers to assault beings who have godlike powers (comparatively), they know the area well, they've been observing their enemies for a long time. And they're strong as hell. Ewoks are seen effortlessly lifting boulders the size of their torsos and throwing them. While it's obvious that the 'boulders' were props made of styrofoam, from an in-universe point of view, we must assume they were rock.
I don't care HOW good your armor is, the kinetic force of that much rock, at that velocity, will knock you silly. And what happens when you find yourself on your ass, concussed, surrounded by primitive creatures with the strength to rend you limb-from-limb? We should be glad for the artful cuts the movie makes.
I could go on, but this has already been long enough in the typing.
In short, the times when we see stormtroopers 'sucking' are all times when their hands have been tied by politics, overarching military strategy, or their superiors incompetence.
The times we see them doing their jobs without such problems, they perform exceedingly well.