Prosumers play a central role in current distribution networks. Local markets provide an environment for prosumers to interact with each other, either directly through peer-to-peer (P2P) markets, or indirectly via community-based markets. In this paper, we propose a hierarchical approach for local energy and flexibility trading among prosumers in distribution networks, in which prosumers are able to trade energy via P2P manner and transact flexibility in the local energy market to maintain distribution network constraints. The proposed method enables prosumers to manage their resources and participate in a P2P market by submitting their optimal bidding and offering curves. A local market operator runs the P2P market for energy trading among prosumers, and cooperates with the distribution system operator to dispatch the flexibility provided by prosumers. Moreover, a real-world distribution network consisting of ten prosumers is considered to assess the performance of the proposed model for local energy market based on flexible behavior of prosumers in the bottom layer of the distribution network.