Always use the longest possible fasteners for the best joint. Because two-by-fours are 1 1/2 inches thick, the best available size in most screws is 2 1/2 inches. This allows 1/2 inch for countersink to prevent the screws from protruding through the back of the boards. Depending on the lumber, you might need to drill a pilot hole to get the screw started. Clamps also help to hold the pieces in place as you insert the screws.
Wood screws are the most expensive option. They do not have threads running all the way to the top, allowing them to pull the wood together. The metal that most wood screws are made from is softer than some other fasteners, making them easier to strip or causing the shaft of the screw to shatter. The threads of wood screws are the most aggressive, meaning they are less likely to pull out or strip the wood. Use a screwdriver rather than a cordless drill or screw gun to drive wood screws so as to prevent stripping the screw head or breaking the shaft. In a 2 1/2-inch length, the shafts of wood screws are thick enough to require a pilot hole for driving them in fully.
Drywall screws are designed to run into the two-by-four framing behind your drywall. This makes them ideal for making joints in dimensional lumber. They come in two basic varieties: coarse or fine thread. The coarse thread makes a stronger joint but requires more force to drive. The fine thread drive easier but are more prone to stripping and breakage. Drywall screws tend to be brittle and can shatter if driven too tight. They are, however, the least expensive option and the choice of many carpenters partly for that reason.
In between wood screws and drywall screws in size, the treated deck screw is a fairly new tool in woodworking. As the name suggests, they are treated to resist corrosion and designed for exterior use. Their fairly aggressive thread and shaft, which is slightly thicker than a drywall screw shaft, make them both easy to drive and strong. The heads are coated like the body of the screw, making them less susceptible to stripping. They are more expensive than drywall screws but cheaper than wood screws.