The first key to figuring this out is getting your coordinate system correct. There are two commonly used coordinate systems for such things. They are the Earth Centered Earth Fixed (ECEF), and Earth Centered Interial (ECI) frames. At midnight, these two line up exactly, but they diverge in other times, based on the rotation of the Earth. ECEF works best for things on the Earth (If you are not moving, you should have 0 velocity. ECEF takes this into account, ECI velocity will have you move with the rotation of the Earth), ECI works best for things in Orbit (Orbiting objects don't care about the rotation of the Earth, at least, the physics doesn't care). Make sure the coordinate systems are correct!
Okay, so you have a position and velocity in ECI coordinates, what do you do? There is an excellent paper that describes the entire process, which I will copy the end formulas here. There is also a few good sources here, here, and here. I highly recommend reading them carefully. Uncertainty is much more difficult, so let's just assume you have a perfect knowledge of velocity and position. Specifically, the 6 classical Keplarian Elements are eccentricity (e), inclination (i), right ascension of the ascending node ($\Omega$), argument of perigee ($\omega$), semi-major axis (a), and time of perigee passage ($T_O$).
I should mention that I am primarily following the Laplace Method of Orbital Determination, there is a competing methodology known as the Gauss Method. But finally this came down to deciphering Matlab code.
Semi-Major Axis
$W_s = \frac{1}{2}*v^2s - \text{mus}./r;$
$a = -mus/2./W_s$; %semi-major axis
Eccentricity
L = [rs(2,:).*vs(3,:) - rs(3,:).*vs(2,:);...
rs(3,:).*vs(1,:) - rs(1,:).*vs(3,:);...
rs(1,:).*vs(2,:) - rs(2,:).*vs(1,:)]; %angular momentum
$p = \sum{L^2}./mus;$ %semi-latus rectum
$e = \sqrt{1 - p/a}; %eccentricity$
Inclination
$I = atan(\frac{\sqrt{L(1,:)^2 + L(2,:)^2}}{L(3,:)});$
Arguments of Pericenter
$\omega = atan2(\frac{(vs(1,:).*L(2,:) - vs(2,:).*L(1,:))./mus - rs(3,:)./r)./(e.*sin(I))}{((\sqrt{L2s}.*vs(3,:))./mus - (L(1,:).*rs(2,:) - L(2,:).*rs(1,:))./(\sqrt{L2s}.*r))./(e.*sin(I)))}$
Longitude of Ascending Node
$\Omega = atan2(-L(2,:),L(1,:));$
Time of Perigee Passing:
$T_0 = -(E - e.*sin(E))./\sqrt{mus.*a.^-3}$