As a supplement to BillC's questions about finding optimal bet size, let me address the other major optimization question for online bonus play: finding the optimal target when playing a non-cashable, a.k.a. sticky, bonus.
This is probably a question of greater practical interest than choosing bet size. First, because choosing the right target makes a much greater difference to your bankroll growth. Second, because, as GBV has remarked below, many bonus hunters are psychologically inclined to choose targets that are much too small; having a mathematical way of choosing the optimal target can be helpful in counteracting that inclination.
The choice of optimal target is mathematically much more complicated than choosing the optimal bet size; but here is my start at its solution.
Note, first of all, that as far as I can see there's no reasonable way to account for the value of time in choosing a target; the amount of time it would take you to reach your target or bust is too unpredictable. So the only way I see is to simply ignore the value of time, and choose an optimal target purely by the criterion of maximizing long-term bankroll growth, i.e. maximizing CE.
Second, I have chosen to restrict the target to always be an integer multiple of the bonus amount. It is an arbitrary restriction, but the CE it loses you is very small, and it greatly simplifies the mathematical problem.
Suppose that you have reached in your casino account a total of N*B (where B is the bonus amount and N is some integer). This total includes your deposit, your non-cashable bonus, and the profit you've made in your play so far. Given the restriction to integer multiples of the bonus, your choice is either to cash out or to continue play in an attempt to reach a target of (N+1)*B.
If you do continue play, playing until you've either reached (N+1)*B or busted; and assuming you play a game with a house advantage of HA; then your probability of reaching (N+1)*B is
P = (1-HA)*N/(N+1)
If you reach your target, you've gained B. If you bust, you've lost (N-1)*B (since your N*B total includes the non-cashable bonus). So the EV of playing for the (N+1)*B target is
EV = P*B - (1-P)*(N-1)*B
And the variance of that play is
VAR = P*(B-EV)^2 + (1-P)*((N-1)*B+EV)^2
If your Kelly-equivalent bankroll is KEB, then the CE of this play is
CE = EV - VAR/(2*KEB)
If CE is positive, that means that N*B is below the optimal target. The optimal target is given by the lowest value of N for which CE is 0 or negative.
It would be nice to find a closed-form solution that provides the value of N at which CE=0; but I have not managed to do so. In the pre-UIGEA days I had a simple program I wrote that implemented the above equations; took as input the values of B, HA and KEB; printed the value of CE for all values of N starting from 1; and stopped the first time it got a negative value.

