Identifying the two-hole torus with an octagon
Edit/disclaimer:
Although the solution below does indeed identify the two-hole torus with an octagon, it does not answer OP's question which was the two-hole torus can be represented by the octagon with opposite sides identified. I do not explain how to identify the opposites sides of an octagon, but rather how to glue two representations of a torus to get a two-hole torus.
Original answer:
Basically, what you want to do is to glue two tori.
Both tori can be identified with the following representation:
Now to glue them together, you want to cut a small piece of each torus, and glue them in a certain way on the area you cut. We are going to cut a small triangle at points $p$ and $q$ as following way:
Note that $p$ and $q$ are note at the same place in both tori!
Now we glue them together, $p$ goes on $p$ and $q$ goes on $q$ which gives:
Redrawing it as an octagon, it gives:
The space resulting from gluing opposite edges of an octagon naturally depends on the orientation of the gluing, but assuming "antipodal edges" are glued with the same orientation, as when building a torus from a square, the result is indeed a two-holed torus.
It's easy to see that
- Two vertices that are endpoints of a dashed segment are identified, so all eight vertices are identified. Consequently, the interior angles of the octagon are joined cyclically; after identification, the vertex has a disk neighborhood.
- Each edge is identified with the opposite edge, and no others, in a manner compatible with the orientation of the octagon.
It follows that the identification space is an orientable surface having a cellular decomposition with one vertex, four edges, and one $2$-cell. The Euler characteristic is $\chi = 1 - 4 + 1 = -2$. By the classification of surfaces, the glued octagon is a two-holed torus.
(Presumably the same conclusion can be reached by surgery, modifying the octagon to the "conventional" gluing, though I haven't checked carefully.)