In this article, we consider a buffer-aided two-way relay network in which a wireless-powered relay acts as an intermediate node for exchanging the data between two sources. The relay applies a time-switching (TS) policy to switch between data decoding (DD) and energy harvesting (EH) modes. Due to the presence of data queues at the relay, the relay is capable of employing opportunistic network coding (ONC) for transmission of the packets. Based on some realistic assumptions, we derive the stability region of such a network through designing TS and ONC policies. It is proved that the stability region is characterized by the TS policy and zero-wait ONC policy. Moreover, we derive the throughput-optimal and power-optimal policies and show that these policies provide the maximum coding opportunities. Also, we derive the average delay of an applied TS-ONC policy at the relay through modeling the data queues and energy buffer of the relay by two inter-related quasi-birth-death processes. We show that although waiting in ONC does not contribute to throughput-optimal and power-optimal policies, it can reduce the average delay. Finally, through simulation, we confirm our analytical results.