Yes, acrylic latex caulk, the cheapest you can find, works very well for both cases. The secret with the track, though, is to us just a thin smear of it...not so much that it wells and beads up between the ties when you press it into place.
I do use nails, but only when I need to keep the tracks in place on a curve or where I have a gap and want to keep strict alignment, but I remove them once the ballast glue has dried. The ballast should keep your tracks aligned throught the layout plan.
Note that you can get latex caulking in several colours, and even stuff that dries clear if that is a concern.
-Crandell