How long did the US occupy Germany and Japan in a large scale after World War 2?

It kinda depends on how you define "occupy". Todays military bases in both Japan and Germany are offshoots of the original occupation. Widespread occupation in both cases remained at least a year or so after the cessation of hostilities and gradualy coalesced into military bases as the respective governments became able to maintain peace on their own. We still maintain a large number of bases in both countries. There was no specific "turn over the reins and leave" point as some want to occur currently in Iraq. The island of Okinawa, for example, was not returned to Japanese control until 1972, prior to that it was governed by the Americans.