what is wrong with my transmission? on 2006 Ford F-150

my truck runs fine, its when im stopped for certain periods that my transmission sounds like its shaking and the rpm guage varries from 500 to 1200 rpms. and if im parked for long enough the enguine sounds like its trying to shut off. this doesnt happene every time but it happens enough for major concern.

Asked by for the 2006 Ford F-150
engine or transmission?