In this paper, network-aware clearing algorithms for local energy markets (LEMs) and local flexibility markets (LFM) are proposed to be sequentially run and coordinate assets and flexible resources of energy communities (ECs) in distribution networks. In the proposed LEM clearing algorithm, EC managers run a two-stage stochastic programming while considering random events by scenario generation and network constraints using linearized DistFlow. As one of outcomes, maximum available up-and down-regulations provided by ECs are estimated in LEM and communicated to LFM. In the distributed LFM clearing algorithm, an iterative auction is designed using a dual-decomposition technique (Augmented Lagrangian) which is solved by consensus alternating direction method of multipliers. The LFM algorithm efficiently dispatches the flexibility provided by ECs in operating time while considering flexibility local marginal price as pricing method. Network constraints are included in the algorithm with an AC distribution optimal power flow for dynamic network topology in which branches and buses are decomposed to solve the problem in distributed fashion. The designed LFM algorithm can respond to exogenous and endogenous signals for flexibility requests. The simulation results in a test case display effectiveness of two proposed LEM and LFM algorithms for an efficient provision of flexibility.