Ford F150 2004 help can't find what is wrong?

I have a ford 2004 4.6L XLT and it had this knocking noise, so I replaced the motor and when I turn the truck on it shakes when idle, but when I accelerate the shaking stops also it has the check engine light from the old motor and I scanned the new motor and get the code P0351 and P0356.

Added (1). Sorry for my grammar

The PCM is likely to be the problem, which means you changed the part that wasn't the problem. The Check Engine is not related to the old, but the current conditions. The PCM is connected to the coils on each plug/cylinder. It affects the timing and order of firing of the plugs.

http://www.v8sho.com/SHO/CoilOnPlugTest.htm

This is a common and expensive problem to fix. If not fixed soon, it can also destroy both the engine and transmission. Start with the PCM and then the coils. The coils are all fed from a single 12V source. The grounds go back to the PCM individually and there's where the switching occurs to fire them.

There appears to be an intermittent low voltage condition at the PCM that causes all the symptoms you described. You may want to take it to a dealer and reflash your PCM then clear the codes. There should be no or minimal charge.

http://www.ford-trucks.com/forums/1036995-intermittant-self-correcting-misfires.html
http://www.rav4world.com/forums/99-4-3-mechanical/81955-p0356-code-plus-7-other-codes-might-bad-coil-2006-v6-61-000-miles.html