It suffices to count the punctures and boundary components. For each puncture or boundary component, the loop around it gives a conjugacy class in the fundamental group, well-defined up to inversion. It suffices to characterize which conjugacy classes arise from this construction applied to both punctures and boundary components, as by counting we recover $n$ and $b$, and then using the Euler characteristic we recover $n$.
For a puncture, a necessary and sufficient condition is that the conjugacy class be sent to a unipotent element in $PSL_2(\mathbb R)$ and not be a nontrivial power of another conjugacy class in the free group. The necessity is straightforward. For sufficiency, we need to observe that as soon as an element of $\pi_1$ is sent to a unipotent element of $PSL_2(\mathbb R)$, we can find closed loops representing the element whose lengths converge to zero, which must in the Riemann surface lie in a small neighborhood of a puncture, hence must be a power of the standard loop around that puncture or its inverse.
For a boundary condition, a necessary and sufficient condition is that the the conjugacy class be sent to a diagonalizable element of $PSL_2(\mathbb R)$, that one of the two components of $S^1$ minus the fixed points of that element contain no limit points of the group, and that the conjugacy class is not a nontrivial power of another conjugacy class. We can rephrase the last two conditions as saying that , for one of the two components of $S^1$ minus the two fixed points, every element of the group that sends a point in that component to another point in that component is an integer power of the chosen element. The proofs of necessity of both of these characterizations are fairly straightforward from drawing the fundamental domains, and the proof of sufficiency is clear from the definition you gave with boundary components.
You might find the boundary component characterization unsatisfactory as it is not clear how to compute with it. On the other hand I suspect the puncture characterization can't be improved much - this is essentially what one uses to count cusps of modular curves, for example.