From what I understand, you have two triads and want to calculate the quaternion which rotates the first into the second.
(1) calculate the direction cosine matrix( aka rotation matrix). This is the matrix with components $DCM_{ij} = \tilde{e}_i^0\cdot e^0_j$. You can calculate this because you know the components of the triads.
(2) Compute the quaternion from the DCM. This is covered here and can be found on most books concerning attitude dynamics, rotation theory, etc.
A more complicated alternative is to use the QUEST algorithm (or $q$-method, or TRIAD). See here, here, and here for instance.