In this study, an air gap membrane distillation (AGMD) system at pilot scale is applied for purification of effluent from a municipal wastewater treatment plant. A district heating network (DHN) is considered as a heat source for the membrane distillation system. Removal performance of pharmaceutical residuals, specific heat demand, and economic assessments were analyzed on the membrane distillation plant. Almost all targeted pharmaceutical compounds were removed to a very high degree, often below the method detection limit. The heat requirement for the MD process could be sufficiently supplied by the low-temperature district heating return line. Specific heat demands for the AGMD ranges from 692 to 875 kWh/m3 without heat recovery and as low as 105 kWh/m3 when heat recovery is possible. Different approaches to integrating the MD within the DHN system were analyzed; the advantages and shortcomings of each are discussed with emphasis on the MD system’s capacity requirement and annual heat demand. The thermoeconomic analyses from this study presented the potential for energy optimization regarding heat recovery and module design improvement of the current MD equipment.