There are three crucial resources at container terminals; the yard, cranes and the vehicles. The main objective of the terminal is the efficient use of these resources while performing different operations. The yard is a temporary storage area where containers remain until transported to their next location by truck, train or vessel. Containers are stacked on top of each other in order to utilize the yard space efficiently. However, stacking cranes can only directly access those containers at the top of the stack. As a result, reshuffling/shifting occurs, defined as an unproductive move of a container required to access another container stored underneath. We focus on increasing the efficiency of the yard via consideration of the container stacking optimization problem for transshipment, inbound and outbound containers at a container terminal. The objective of the problem is to minimize container storage and retrieval times through avoidance of reshuffles, resulting in more efficient loading/unloading operations, and in turn minimizing the dwell time of containers. The main inputs are the type, weight, discharge port/location, destined vessel/vehicle of the container, and the expected departure time. Different stacking policies are proposed in this study, and we also investigate the problem of allocating the transit container to outbound vessels to minimize dwell time at the terminal. Transit containers require multiple sea-trips to reach their final destination. Vessels departing from the terminal and destined for the same port may provide exchangeable trips for this type of container, based on their several attributes and capacity restrictions. We consider this problem taking into account several factors that affect container/trip allocation decisions. The solution of this problem also has implications for the stacking problem.