Removes the phosphate from trehalose 6-phosphate (Tre6P) to produce free trehalose. Also catalyzes the dephosphorylation of glucose-6-phosphate (Glu6P) and 2-deoxyglucose-6-phosphate (2dGlu6P). alpha,alpha-trehalose 6-phosphate + H2O = alpha,alpha-trehalose + phosphate Magnesium. Can also use other divalent metal cations as manganese, cobalt or zinc. Optimum pH is between 6 and 7.5. Glycan biosynthesis; trehalose biosynthesis. By cold-shock, osmotic-shock and during the transition to stationary phase. Expression is partially dependent on RpoS. Belongs to the trehalose phosphatase family.