Given a threefold $Y$ containing a surface $S$. Under which conditions can I contract $S$ so that I still end up with a smooth variety?
In other words



> 
> what are the conditions for the
>  existence of a smooth variety $X$ and
>  a morphism $Y\rightarrow X$ such that
>  the image of $S$ under the morphism is
>  a curve and the morphism is an
>  isomorphism away from $S$?
> 
> 
> 


What are the conditions when $Y$ is a fourfold and $S$ is still a surface?



When is  a surface in a threefold  contractible to a curve?
You want a divisorial contraction $Y \to X$ on a smooth 3-fold $Y$. *Extremal* divisorial contractions (i.e., contractions associated to a $K\_Y$-negative extremal ray in the Mori cone of $Y$) have been classified by S. Mori in his paper 


[*3-folds whose canonical bundles are not numerically effective*](http://www.jstor.org/stable/2007050), Annals of Mathematics **116**, No. 1 (1982), pp. 133-176. 


Looking at Theorem 3.3, we see that here are exactly the following possibilities:


1. the smooth blow-up of a point; in this case $S$ is isomorphic to $\mathbb{P}^2$ with normal bundle $\mathcal{O}(-1)$;
2. the smooth blow-up of a curve, in this case $S$ is a ruled surface whose normal bundle restricted to the ruling has degree $(-1)$; this is the situation described by Donu Arapura in his answer;
3. the contraction of a plane $S$ with normal bundle $\mathcal{O}(-2)$; in this case the 
surface $X$ has an isolated singularity isomorphic to the quotient of $\mathbb{A}^3$ by the involution $(x,y,z) \to (-x, -y, -z)$;
4. the contraction of a smooth quadric $S$ whose rulings are numerically equivalent; in this case the image of $S$ is a single point, which is a singular point for $X$;
5. the contraction of a singular quadric $S$; again, the image of $S$ is a point in $X$.


Summing up, if you want that $X$ is smooth and the image of $S$ is a curve, the only possibility is 2. 


In the case where $Y$ is a smooth 4-fold and $S$ is a smooth surface, the answer can be found in the paper of Kawamata "Small contractions of four-dimensional algebraic manifolds": in this case the only possibility is that $S$ is the disjoint union of copies of $\mathbb{P}^2$, with normal bundle $\mathcal{O}(-1) \oplus \mathcal{O}(-1)$


