Best Bets
According to the official Prima game guide (Engaging Vehicles, p. 16), your best option is the M320 grenade launcher, which you'll unlock very early. And that's not at all an ideal option since you won't be doing nearly as much damage as a rocket, mine, or tank would do. My feeling is that it's like throwing rocks at a rhino. Sure, eventually you'll do damage, but long before you do enough damage it'll figure out where you are. Bad scene. And as for helicopters, good luck getting them to stay still long enough for a grenade launcher takedown.
Note that if a chopper or heavily armored vehicle is very badly damaged (spewing smoke), it might be worth a grenade launcher or even a grenade attack in the hope of shaving off those last few hit points. But don't expect miracles.
Small Arms Fire
Small arms fire won't damage heavily armored vehicles. You can damage some light vehicles with small arms fire, but don't count on fast results.
As a better strategy you can damage people in the least-armored vehicles, buggies and jeeps. If you pull it off, as a bonus you get an intact vehicle to jack.
M320 Example
As an example of probably the best case scenario, grenade launcher vs. lightly armored vehicle: Earlier tonight I disabled a couple of APCs with four grenade launcher rounds each.
Though I can't complain about the result, in one case the APC had no gunner and the driver didn't jump out, drive away, or hop in the gunner's seat. In the other case the gunner... uh... had suboptimal situational awareness. And that's just disabling, not outright destroying; an engineer could have repaired them.
Against slightly more skilled opponents, or on a fully populated server, I doubt I would have have survived either attempt. To pump out four grenades takes a good 10-15 seconds including reload time.
What you can do
So as a rule, leave it to engineers with their rockets and mines, support with their C4, and people in vehicles.
Perhaps the most useful thing you can do as light infantry is to spot enemy vehicles. Just because you're not blowing it up yourself doesn't mean you're "completely useless". Spotting is actually very valuable, and it's disappointing how infrequently most players do that.
As you already guessed, underslung attachments replace your primary kit, just like the normal grenade launcher would, which would be, as in the example of the assault class, the medkit.
You switch to your underslung attachment by pressing what you normally press for the medkit, you will then switch to your grenade launcher. You can verify that by observing the slightly raised barrel stance of your rifle.
If you haven't chosen the underslung rail as attachment option, then you will access to the grenade launcher as a separate gun, which will cause it to take longer to switch to and back.
For more information, take a look at this Wiki page.
Best Answer
The 1 and 2 keys (PC, not sure about the console controls) activate your main weapon and secondary weapon, respectively. This is of course the same in tanks (or any vehicle with a secondary weapon, for that matter) as on foot. The main weapon in the tanks is always the tank's main gun.
You select what your secondary weapon will be in the customize menu.